News:

Simutrans Wiki Manual
The official on-line manual for Simutrans. Read and contribute.

Haskell (formerly: Languages, got to learn another one)

Started by sdog, October 19, 2012, 11:35:08 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sdog

I've put a bit of thought into C/C++ programming and decided not to learn it. The disadvantages are just too large. (fiddling with low-level stuff the compiler ought to do, very unsafe, unreadable, memory management!). For all purposes C/C++ would be useful to me, i can use Fortran and rather invest energy in getting better with that [which is in general also quite a bit faster].

What i'd need though is a quick to code language, Perl isn't really doing it. Very nice to code, when i cand do it in one day. No need to comment code or make it readable, since it is in vain it's more efficient to write a completely new script next time i need it (worse is better). But multi dimensional arrays suck badly, all advanced libraries are a pain to use etc. As soon as there's a matrix or numerical integration involved it is not effective.

I've posted below elsewhere, and thought here's quite a lot of experience from people i know. So i'll cross-post it here too.



I'm comparing a couple of languages for my purposes.* Might have a look into one or two of them. This is just a first glance, so feel free to correct me and add aspects.


Advantages
Haskell
pure (functions with no sideffects)
code looks rather nice and readable

Erlang
concurrent (no shared memory)

ATS
roughly as fast as fortran
focus on scientific computing


Drawbacks
*Haskell*
no built-in linear algebra (blas avaiable though)

*Erlang*
no built-in complex numbers
not even simple linear algebra libraries available

*ATS*
new, very small community still
not so much simpler to use


*I've come to realise, i need something besides Fortran and Perl, one is for coding small things too heavy and the other sucks too much with matrices. The last thing i coded in Fortran had two dozen lines for the algorith and 100 lines of overhead, i also spent about five times more time on the whole periphery (especially the awfull in/output).
Collapse this post



(i'm not looking into Python here for psychologica reasons. It's too close to Perl, and i wouldn't learn it. perhaps if i got to something different, then i could come to Python. Which is perhaps one of the most useful language to know at the moment.)



update:  i should like to add that ATP is in ML tradition, and seems in many aspects to be similar to OCaml


Edit:
changed title to Haskell

kierongreen

Haskell gives me serious headaches, and I find the code ugly... I didn't find it useful for doing anything serious (yes I know you can write compilers and many other large projects in it, I obviously just don't get it). I've not looked at the others you've thought about.

If you find C/C++ ugly and unreadable then unfortunately I'm guessing you'd think the same of Java. Other than that Java avoids many of the low level aspects of C/C++, has memory management and is more "safe".

It really depends on what you are doing - if you are making a large application then C/C++ (or to a lesser extent similar languages, Java, C# or whatever Microsoft is up to these days etc.) is really the only way to go I think. It is perfectly safe and reliable, as long as your  programming is...

On a less serious note... ever tried Assembler :p

isidoro

Even less serious: try TeX.  After that, everything would be easy for you...  ;D

sdog

Thanks a lot on the comment on Haskell.

I ought to add, a terminal, taking half my screen, has 68 characters (when at a readable size). :-)

More seriously i've tried java some years ago, but i never managed to remember even the simplest builtin functions. always had a browser instance with google ready on the second screen. Not speaking from experience, the power of Java seems to be mostly in the frameworks available, while the language in itself isn't very elegant. Accordingly it's a favourite of businesses, and the largest part of the learning curve is learning the conventions, workflows and use of frameworks. [expecting of the programmers to know the basics rather well].

That's not my intendended usage, what i'll mostly use it for things i do on my own, and standalone.


tl;dr
i didn't want to say just no, to a very reasonable and helpful suggestion.




@isidoro
i'm already spoiled by LaTeX
only had a few brief looks into actual TeX  [btw   LaTeX + git   the most useful combination since doing so with ink and paper!]

Markohs

  I'd say erlang is the best one from your list. Never programmed in erlang personnally, but a workmate of mine tells me very nice things of that language. The ease to distribute code and use networing is quite built in there. Sound interesting.

But if you want to learn a language that has some professional importance, I'd go personally for javascript (I like this one a lot, it's a very nice language, it has prototyping as a way to implement object-like structures, and clausures, it also considers functions as variables. I personally find it very interesting). the way types are handled it's a bit ugly, through, and array iterators are not nice.

And PHP, ofc.

sdog

#5
Erlang has perhaps the biggest future of the above languages. (If not itself, then by it's concepts copied). I ought to have another look to find out how well it does with very basic linear algebra.



@isidoro
http://en.wikipedia.org/wiki/LuaTeX

(it's features are quite interesting, especially towards OpenType. Perhaps the TeX for the next 20 years?)




update:
As a future referene: Apparently Haskell, Erlang (and OCaml) have nice "Try it in your browser" websites:
http://tryhaskell.org/
http://www.tryerlang.org/
http://try.ocamlpro.com/

Ters

What is the motivation for learning another language? If it is only out of curiosity, there are many options. When it comes to actually getting something done, options become more limited depending on what you want to do. C and languages inspired by it (or at least looks that way, all the way to PHP and JavaScript) are probably used for the vast majority of applications made since the 1990s. In niches, like AI and mathematical applications, other languages rule. Combining multiple languages into a single application is also normal, and allows you to use each language for what it is best at.

At a recent Java developer conference I was at, a panel debate concluded (thought it wasn't really what the debate was about) that the most important thing a developer should learn, is to learn new languages.

Dwachs

@sdog: what kind of problems do you solve with your programming?

Why not using matlab (or its freeware companions) ?
Parsley, sage, rosemary, and maggikraut.

prissi

You could also use squirrel in simutrans scripts ...

isidoro

Quote from: sdog on October 20, 2012, 02:14:39 AM
http://en.wikipedia.org/wiki/LuaTeX

I've tried it and it makes the difference compared to pure TeX.  But it inherits something from its father... ;)  Seriously, consider Lua.  But more seriously, give it a try to Python.  Forget your prejudices.

sdog

Thanks a lot for your replies, it's quite an interesting read.

@isidoro
Lua is rather interesting, and somewhat surprising.

@prissi
first time i heard of squirrel. The name alone would be enough reason to learn it. Nothing beats answering to someone: "I'm fluent in squirrel, but only written."

@Dwachs
at the moment learning some numerical methods, by implementing the algorithms. i'm a bit strange in a way that i sometimes understand things in code better than with pencil and paper. (and i have to say, it's about as readable as Ook)
In general it's some minor tasks like analyzing some data (integrating, some combinatorics, etc), at times i just want to test something.

I tried octave (which is somewhat similar to mathlab) but never got very deep into it
I'm using octave's interactive shell quite frequently as a scientific calculator. Do you think it's worth investing time into it, instead of learning a general purpose language? [cool thing is, octave is on my wive's phone now :-)]

@Ters
It doesn't matter if it is by itself used in possible jobs, what matters there is not the language itself bu the method competence. One can't guess what'll be needed in the future anyways. I doubt i'd go in any area where Java or C are requirements, i'm not a programmer or CS. Quite a lot of what you said directly points to Python. Glue language, very widely used in experimental Physics (most new lab automation is being written in Python now), very widely in other areas too.

I'm a bit reluctant to go too deeply into my professional outlook in the open [only devotees participating, could be moved to the lounge], some adaptability might be required though.



Some kind of intermediate conclusion. In a not too long time-fram i will learn Python. At the moment  i'm rather interested in functional languages and still want to learn one of the more obscure languages above. ATS is out, since it is too new, OCaml is in but not a favourite. (i can't understand OO, especially in a functional language) Haskell and Erlang i'll just try a bit in parallel. See how far i get. They can teach me functional programming [perhaps also changing my approach in imperative languages] and concurency.

Fabio

I recently leant Scheme as a fast way to script gimp. It's a rather interesting language.

I'm also fluent with VBS/VBA, which serves my purposes well enough.

Dwachs

The big advantage of matlab is that it lets you plot data very easily. I use it extensively for numerical computations. I did not try octave/scilab as our department has matlab installed :)
Parsley, sage, rosemary, and maggikraut.

sdog

#13
the first good that came out of it, is i think i got what polymorphism means.

it seems to be the same as one does in fortran with the slightly awkward construction in module interfaces

interface myfunc
  module procedure myfuncA, myfuncB
end interface tostdout
[...]

contains
  function myfuncA(a)
    real, intent(in) :: a
[...]

  function myfuncB(b)
   real, dimension(:), intent(in) :: b
[...]


where myfunc is a function and the others are functions taking an argument of different types.

Less obviously it seems to be polymorphism that builtin real functions are taking single, double and quadruple real values and returning the corresponding type. Without actually requiring the d form (eg cos, dcos, sqrt, dsqrt; where the d-less was the single form in F 77)



The first uncomfortable thing encountered:
Neither Erlang nor Haskell use arrays by default. I was completely  ignorant of lists (thought it's just a fancy name for arrays). Using arrays is possible, but not very convenient.

Ters

That Fortran code looks like what I know as function overloading. I wasn't aware that that is also seen as a kind of polymorphism until I checked Wikipedia. I'm more used to think of polymorphism in terms of object-oriented programming, where a single function accepting a Vehicle, can also be passed a Car, since a Car is a Vehicle. That should also be possible in one of the newer versions of Fortran, but I've never really learned that language well, just helped teaching it.

Just proves that there is always something left to learn.

sdog

#15
That OO example seems to be a special case, with one type being a subset of another.

i've never gave much thought about forming new types. And i do have difficulties to see things like Car or Vehicle as types. (But that's perhaps why i fail with Objects in OO) For all what i did/do the basic types are enough. That's the thing with having very inhomogenous data, also containing nasty things like strings etc.

That's something i've been surprised lately, how much is written about how languages are dealing with strings and such. This is rather surprising me, always thought that would be some niche thing. (eg, what does it matter to me what's in a database

"[...] I've never really learned [Fortran] well, just helped teaching it."
I've learned who to ask when hitting a wall. Please send me your email, social networking, snail mail addresses + phone numbers and emergency phone numbers :-P

ps.: didn't Dijkstra say something along the lines "Fortran destroyes the mind, teaching it must be seen as a criminal offense."




@Fabio: Scheme sounds pretty cool, nothing beats "Baby, wanna see my Lisp" when trying to hit on a girl, [who's into CS]
Guy Steele is also at the beginning of this, i wouldn't talk here if Sun hadn't fumbled Fortess [or rather DARPA weren't too thick]

Ters

Actually, the students I helped with their assignments (which I and another fellow student had selected from a book) generelly just wondered why they were though Fortran in the first place, when they could just use Matlab. I think some of them even knew that that was what was used by the profession they were studying for (some oil and geology related thing, I believe).

isidoro

Fortran 77 is plain garbage.  And Fortran 90 and successors are garbage with potatoes, imho...  :)

I also had to suffer it some time.  Happily, I recovered and now I can hardly remember it...

sdog

#18
Most hate Fortran, for a good reason, four reasons why it still is so widely used:

(1) intrinsic complex functions,
(2) ibraries and old code,
(3) intrinsic matrix multiplication
(4) it's the fastest language for scientific computing.

for reason one 77 is still written, and (pre 77 still used)

From hearsay: Concurrent programming is a pain with it, but much less so than with C.
(gladly our stuff is so embarrasingly parallel, that the PBS takes care of all parallelisation. As a single threaded process for one parameterset my stuff runs through in half a day on a consumer cpu :-)

Markohs


sdog

portable batch system, sorry wasn't thinking when writing. WP: "Portable Batch System (or simply PBS) is the name of computer software that performs job scheduling. Its primary task is to allocate computational tasks, i.e., batch jobs, among the available computing resources."

Markohs


IgorEliezer

Just for heck of it, let me introduce the weird world of AutoLISP:


Full image

Not that I'd want someone to learn it, I'm just sharing my experience. AutoLISP is a dialect of a very ancient language, the LISP, made specifically to develop applications of Computer-Aided Design, you know, the stuff the engineers and architects do. When I'm codding, I feel as if I'm writing down pretty straightforward formulas between parenthesis (that's why LISP is also known as Lost In the Stupid Parenthesis) and the syntax is quite consistent, it's always (function argument1 argument2 argument3 ......argumentN) and I can nest an operation inside the other. So something like:

2.0 x (5.7 + 0.2 + 1.5)
           3.0 - 1.0

is codded:

(/ (* 2.0 (+ 5.7 2.0 1.5)) (- 3.0 1.0))

A variable can accept any kind of value with no need of declaring the type, of course I can't use an 'int' variable in a string function if I don't convert it first (hence the itoa function  ;) ), or it will return error.

I tried to learn Java this weekend, just for fun.... hell, what a such craziness! It made me love my AutoLISP and its barebone IDE even more. Unfortunately I don't have mind anymore to learn new stuff.

Fabio

Lisp, so we're related, as I speak the scheme dialect ;)
It's rather easy to grasp and the nesting is powerful, although the math formulas require a certain degree of mental flexibility as I find them counterintuitive.

sdog

Lisp is cool!
They als pioneered the whole domain specific language concept, no wonder it's used in acad and gimp.


When you already like the functional language, perhaps it's more sensible for you to learn python instead of java?


I like the reverse polish notation.

VS

Python does not have Java's penetration among users, but otherwise works reasonably as multiplatform. I wrote all pak128 scripts on windows, and they "just work" everywhere!

I have my eyes on Erlang, since... forever? I'll never learn it, of course :(

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

sdog

I've got a few hours for this today, and i'm working on understanding recursion (and iteration) in a CS sense.


I rather like the pattern matching instead of conditionals. This seems to have quite an effect on readability. (I just remember the nested conditionals in one of our programs after three levels i'm always lost)

sdog

#27
I've used Haskell a bit now, and i'm very very fond of it.

I was surprised how quickly i got used to immutable state. Reading about it i couldn't understand at all how something could be done at all.* Some aspects of it are very nice and usefull. I've heard of lazy evaluation before, but actually using it was quite straightforward and works quite nicely. Example:

let f a x = [i]some function of a, x[/i]
-- call f once
f a x
-- do so recursively
let xs = iterate ( f  a ) xs

-- not evaulated yet, defines a list xs with all iterated values
-- calling it would now evaluate the "xs =" expression, ad infinitum

take 5 xs  -- evaluates xs for 5 iterations, returns all values
xs!!100    -- evaluate 100 iterations and return the 100th value in the list.


Recursion instead of iteration takes a bit to really sink in. Algorithms can be designed quite differently i think. This needs the most thought. The concept of functional programming itself is much more intuitive than procedural programming (i just got used to the latter first).

There are some good effects on the way i'm programming in overall, the type system is quite advanced and the major difficulty when learning. It is required to think about the type and it's operations when defining a function. This helps also to be more aware of spaces in general (not being sloppy and not just taking all operators one needs for granted).

In effect Haskell completely replaced octave (Mathlab) for me. I'll use perl only for regular expressions. And it will be even more of a pain to look at Fortran.

What i haven't done yet:
A standalone, compiled programm. So far i used only the interactive shell.
Monads. (thus no IO)

Here is a very good explanation of Monads: The first time i found the concept explained in easy to understand terms.
http://cdsmith.wordpress.com/2012/04/18/why-do-monads-matter/


*it is also not completely immutable, since something can be assigned to it in the first place, with the "let" statement.



Just read it allows literate programming in a very nice way, by compiling code in a latex file. That really is a brilliant thing!

IgorEliezer

Quote from: sdog on November 04, 2012, 04:28:28 PM
When you already like the functional language, perhaps it's more sensible for you to learn python instead of java?
I got myself messing around with Python. Blender and some other tools use Python as scripting or whatever.

Any idea of IDE? Typing in the DOS-command is no fun. D:

Quote from: sdog on November 04, 2012, 04:28:28 PMI like the reverse polish notation.
Oh Nice to meet you. I mean, I've never heard of polish notation before. 8)

Fabio

You can use a nice text editor (like NotePad++), save as .py and run from command line.
Modern text editors have a nice multi language (as in programming language) markup.

I even wrote a NotePad++ language markup for Makeobj dat files.

Ters

There's also a simple IDE bundled with the Python install for Windows. I haven't used it, though.

IgorEliezer

Quote from: Fabio on December 23, 2012, 02:01:17 PM
You can use a nice text editor (like NotePad++), save as .py and run from command line.
Yea I did.

# MAH VEREE FURST PAHYTHUN CODEH: FEAR MEE!

print ('*** This is the very first program on Python made by IgorEliezer. Tee-hee!')
print ('2012/12/24\n')

x = int(input("Please enter a non-negative integer value: ")) # get user input and covert it into integer

if x < 0: # checks if it's negative
    x = 0 # change it to zero
    print ('Value = ', x, '. You entered a negative value, silly! Value changed to zero...\n') # prompt user
elif x == 0: # zero
    print ('Value = ', x, ". It's a zero.\n") # prompt user
elif x == 1: # one
    print ('Value = ', x, ". It's a one.\n") # prompt user
else: # bigger than one
    print ("OMG! It's more than one! Get in the car!\n") # prompt user
   
input("Hit ENTER to leave this lame program: ") # this or the program won't let user see what he did.

Well, at least nobody will complain I'm not striving. :D

sdog

I commit the crime of thread necromancy to follow up a couple of years on the following:

Quote from: sdog on October 19, 2012, 11:35:08 PM
I've put a bit of thought into C/C++ programming and decided not to learn it. The disadvantages are just too large. (fiddling with low-level stuff the compiler ought to do, very unsafe, unreadable, memory management!). For all purposes C/C++ would be useful to me, i can use Fortran and rather invest energy in getting better with that [which is in general also quite a bit faster].

This really came back to bite me in the ****.

While I find these points much more relevant than before – I've learned quite a bit in the meantime – not being proficient with C is a drawback looking for jobs. (I've recently finished my PhD in theoretical physics, and since I'm not good enough at it for a career as perpetual post-doc, I am looking for one.)

I've come to a couple of job postings where the company and location is agreeable*, that do not mention Java, C#, or Windows (wouldn't touch any with a 3 m pole). Even when I tick all but one of the requirements, but that one requirement is "programming experience (C/C++)". In other words, need not apply.

It is to be seen if this indeed bites me in the ****, perhaps I can find a job where I can do something interesting enough that there is no need work-life balance, where I can use an intersting but not hackish language, and don't have to leave civilisation. I do have some doubts though.

*there are interesting jobs in godawful places, eg a town with 5k pop in the middle of the 'Schwarzwald', or a Bavarian village where one has to ride the bus for two or three hours to get to the next supermarket! For one of these I found job offers from five hr-consultants.

ps: Isaac, you added a UK-English list to the profanity filter!?  Disclaimer, I should never use asterisks to obfuscate the name of parts of my body or my profanity.

jamespetts

It's never too late to start learning C++ and helping to add some features to Experimental...

Edit: Incidentally, it is interesting that C/C++ is still very much in demand; I thought that statistics had shown that far fewer projects were written in it now than even 10 years ago. Best wishes in the job search, incidentally!
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Ters

Quote from: sdog on October 29, 2016, 08:35:55 PM
I've come to a couple of job postings where the company and location is agreeable*, that do not mention Java, C#, or Windows (wouldn't touch any with a 3 m pole). Even when I tick all but one of the requirements, but that one requirement is "programming experience (C/C++)". In other words, need not apply.

Then I am baffled as to what kind of programming job you are looking for. The only major kinds that remain are web programming, using either JavaScript or Flash.

Apart from that, there are some jobs that involve a bit of programming, but are primarily scientific in nature, but I know little about them. Apparently those looking for petroleum are expected to know Fortran, since I, as I wrote earlier, was an assistant to their teacher at university. And at least some of the geodesists at work program a bit, possibly also in Fortran. The latter in pretty niche to begin with. Most haven't even heard of the discipline, but their fascination for certain phenomena at the edge of the known universe is apparently very important for modern life.