Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
jandrese
Apr 3, 2007

by Tiny Fistpump
Since we appear to have a number of functional language wizards in here, I have a question: Which functional language would you use for a large project?

The reason I ask is because I only know (sort of) two functional languages: Scheme and Erlang. Neither of which have even basic features like type checking or complex data structures (at least not that I was taught). The complex data structure thing is a big sticking point for me, since in a large program it's very likely that you'll build up a considerable amount of state as the program runs, and passing each and every variable on every single function call gets old quickly.

I know Erlang has its key->value database thing, but its use is somewhat discouraged as it breaks the complete thread safety thing Erlang has going on.

From what I saw, the only way to make a complex data structure is to make a list, and just have a magic place for every piece of state, then when you need something you just iterate down the list until you get to the right place. This could be done very elegantly in Erlang with the pattern matching and a second list that has the atoms that you use as the keywords for the list. It would probably only be like 5 lines of code. And it would be a horror because you have a O(n) access struct!

It also doesn't help that the I/O routines that come with the language (both languages) are embarrassingly primitive.

I guessing LISP must be better about this, but it still makes me wary about trying to build anything large in the language.

Adbot
ADBOT LOVES YOU

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

PT6A posted:

Ding ding, you are a winner! It's McGill. Did you have Vybihal for it, out of curiosity?

Don't want to keep this derail alive for too long but no, I got Mahes. An improvement if I base myself on the one class I took with Vybihal, but don't take that as an indication that you should take Mahes' networks class if you haven't; the workload for that is almost on the level of the 4 credit crypto class.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

jandrese posted:

The reason I ask is because I only know (sort of) two functional languages: Scheme and Erlang. Neither of which have even basic features like type checking
http://docs.plt-scheme.org/ts-guide/
this is not a serious suggestion

jandrese posted:

or complex data structures (at least not that I was taught).
http://docs.plt-scheme.org/reference/structures.html

Scheme even has multiple class systems if you want to do OOP in scheme for some reason.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

jandrese posted:

From what I saw, the only way to make a complex data structure is to make a list, and just have a magic place for every piece of state, then when you need something you just iterate down the list until you get to the right place. This could be done very elegantly in Erlang with the pattern matching and a second list that has the atoms that you use as the keywords for the list. It would probably only be like 5 lines of code. And it would be a horror because you have a O(n) access struct!
You seem to have barely scratched the surface of the Erlang language and its standard distribution.

quote:

and passing each and every variable on every single function call gets old quickly.
For a small program, a dedicated process can be used. For bigger, use an in-memory mnesia table.

quote:

It also doesn't help that the I/O routines that come with the language (both languages) are embarrassingly primitive
The io module has printf()/scanf() equivalents and the standard distribution comes with a tokenizer and parser generator (leex and yecc).

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

It's interesting to see so many McGill CS types in here - COMP 202 was the class that inspired me to drop my music degree and go into CS :cool:


jandrese posted:

Way to miss the point. The example there was to show off the weirdness that is running pattern matches on your function calls, the recursion bit was just there because that's how Erlang works!
For somebody who claims Erlang has revolutionized his life and how he codes, you sure had a difficult time coming up with the syntax for writing a factorial function, about the simplest Erlang program there is, from memory. Maybe you were too busy writing proofs and being a mathematician to steal a solution off Google? (As you can probably tell, the "mathematican" comment of yours was the comment that ruffled my fur more than the condescending example "code")

This, actually, proves my point - so many people on the net proselytize the flavour-of-the-week functional language and yet so few have clearly actually used it for anything beyond copying the code examples out of Joe Armstrong's book.

Anyway.

To give a less snotty answer, no, I didn't miss the point. Yes, the pattern matching stuff in Erlang is very cool, but every single other person in this thread saw it with Prolog in their third year of uni, so we don't feel the need to extol the virtues of a programming paradigm that isn't news to us. It's the whole "to a carpenter with a new hammer, everything looks like a nail" maxim.

(additionally, most scheme implementations actually have compound datatypes, though IIRC it's not part of the language spec - in PLT Scheme, for instance, it's defined through the (make-struct ...) construct.)


edit:

Mustach posted:

a tokenizer and parser generator (leex and yecc).
:lol::lol:

Dijkstracula fucked around with this message at 20:55 on Nov 29, 2009

jandrese
Apr 3, 2007

by Tiny Fistpump

Dijkstracula posted:

For somebody who claims Erlang has revolutionized his life and how he codes, you sure had a difficult time coming up with the syntax for writing a factorial function, about the simplest Erlang program there is, from memory.

What are you talking about? Have you confused me with someone else?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

jandrese posted:

What are you talking about? Have you confused me with someone else?
pretty sure I haven't :confused:

quote:

In Pseudocode because I can't remember the wacky syntax:

jandrese
Apr 3, 2007

by Tiny Fistpump
You're talking about factorials, the function was a simple iterator. I suppose iterators are a subset of factorials, but still.

And I can't remember the syntax because it's been a couple of years since I used it, that is all.

I certainly never said that it revolutionized my life, because it did not. I found it to be interesting but have never had a chance to use it in real life, only to build toy programs for class.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Dijkstracula posted:

(additionally, most scheme implementations actually have compound datatypes, though IIRC it's not part of the language spec - in PLT Scheme, for instance, it's defined through the (make-struct ...) construct.)
Even if the implementation doesn't provide them, it's not that hard to add them yourself. PLT Scheme's make-struct implementation is under 200 lines of scheme.

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.

jandrese posted:

I suppose iterators are a subset of factorials, but still.

Thread succesfully underailed.

jandrese
Apr 3, 2007

by Tiny Fistpump
I'm just trying to understand Dijkstracula's comment.

jandrese fucked around with this message at 00:49 on Nov 30, 2009

shrughes
Oct 11, 2008

(call/cc call/cc)
So I've been reading the PostgreSQL manual and discovered this gem.

code:
$ psql
psql (8.4.1)
Type "help" for help.

postgres=# SELECT (7 !);
 ?column? 
----------
     5040
(1 row)

postgres=# SELECT (!! 7);
 ?column? 
----------
     5040
(1 row)
That's right, PostgreSQL has two factorial operators!

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

jandrese posted:

Since we appear to have a number of functional language wizards in here, I have a question: Which functional language would you use for a large project?

Erlang if you need to upgrade it in-place, Haskell if it needs to be fast, if neither of these restrictions apply then flip a coin.

I assume there's somebody still writing in ML or CAML but everybody else has moved on.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
OCaml has a bit of a following although I don't know if it sees much/any production use

mr_jim
Oct 30, 2006

OUT OF THE DARK

Otto Skorzeny posted:

OCaml has a bit of a following although I don't know if it sees much/any production use

When I first learned Ocaml, type inferencing and pattern matching blew my mind. It was also my first introduction to functional programming. I haven't actually written anything in it since college though.

MononcQc
May 29, 2007

It's my turn to sperg on Erlang.

jandrese posted:

Since we appear to have a number of functional language wizards in here, I have a question: Which functional language would you use for a large project?

The reason I ask is because I only know (sort of) two functional languages: Scheme and Erlang. Neither of which have even basic features like type checking or complex data structures (at least not that I was taught).
You need to look into TypEr and Dialyzer for Erlang, static analysis tools that look for discrepancies, type errors, and since the latest release, data race conditions.

http://learnyousomeerlang.com/types-or-lack-thereof#for-type-junkies for more info.

jandrese posted:

The complex data structure thing is a big sticking point for me, since in a large program it's very likely that you'll build up a considerable amount of state as the program runs, and passing each and every variable on every single function call gets old quickly.

I know Erlang has its key->value database thing, but its use is somewhat discouraged as it breaks the complete thread safety thing Erlang has going on.
The key-value databases come in different flavour: ets (in memory), dets (on disk) and mnesia (distributed database with ACID transactions). All of these can be accessed transparently through qlc, an Erlang parse transform that lets you query the databases as a list comprehension.

With ets, you can also set permissions: read/write for all, write private to the owner process/actor only with read public to others, or write/read only allowed to the owner process/actor. This solves the problem with 'thread safety' if the mnesia transactions are not enough. Also, Dialyzer as mentioned above will find race conditions when using ets tables.

jandrese posted:

From what I saw, the only way to make a complex data structure is to make a list, and just have a magic place for every piece of state, then when you need something you just iterate down the list until you get to the right place. This could be done very elegantly in Erlang with the pattern matching and a second list that has the atoms that you use as the keywords for the list. It would probably only be like 5 lines of code. And it would be a horror because you have a O(n) access struct!
You have lists, tuples, records (syntactic sugar for nested tuples), proplists (lists of tuples), arrays, dicts, sets, trees and others. Note that these are implemented as lists and tuples also, but are part of the built-in library.

You could also hack your way with binaries. I've written a little brainfuck interpreter that would use a long binary structure as a tape/array to read on with O(1) access.

If that's still not enough, the R13B03 release from last week now includes NIFs, a way to write functions in C and have them interface with Erlang. Note that this is not a FFI and segfaults in your code will crash the whole Erlang VM the module has been loaded in, though.

jandrese posted:

It also doesn't help that the I/O routines that come with the language (both languages) are embarrassingly primitive.

I guessing LISP must be better about this, but it still makes me wary about trying to build anything large in the language.

What are you looking for for the IO?

Also for a lisp, you might want to give an eye to LFE, a lisp developed to run on the Erlang VM by Robert Virding, who knows his poo poo as no one else does.

-----

Dijkstracula posted:

To give a less snotty answer, no, I didn't miss the point. Yes, the pattern matching stuff in Erlang is very cool, but every single other person in this thread saw it with Prolog in their third year of uni, so we don't feel the need to extol the virtues of a programming paradigm that isn't news to us. It's the whole "to a carpenter with a new hammer, everything looks like a nail" maxim.

Pattern matching is not that impressive, but I guess props have to be given to the error handling functionalities with supervision trees and whatnot, and then the OTP framework which is pretty unique. I don't know, I don't think many other languages have that (maybe Oz?).

Dijkstracula posted:

lol about leex and yecc
neotoma sounds nice if you want a packrat parser-generator library. I never really used that kind of stuff, though.

MononcQc fucked around with this message at 03:31 on Nov 30, 2009

Zombywuf
Mar 29, 2008

If you think that:
  • Programming languages are divided into functional and non functional
  • The reason Scheme is less functional than Haskell is the lack of a static type system
  • The feature that sets Erlang apart is discriminated unions
  • Have never heard of multi-agent ontology oriented programming
then it's you. You are the horror.

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

shrughes posted:

That's right, PostgreSQL has two factorial operators!
I always use a DBMS to do my factorials anyway, so it can't hurt to have options!

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Dijkstracula posted:

edit:
:lol::lol:
Is this a "lol they suck?"

MononcQc
May 29, 2007

Zombywuf posted:

  • The feature that sets Erlang apart is discriminated unions

I have never heard of anyone associating discriminated unions and Erlang. I don't know, I've always heard of the term used with languages supporting ML-like type systems. Where is this coming from?

tef
May 30, 2004

-> some l-system crap ->

Dijkstracula posted:

Yes, the pattern matching stuff in Erlang is very cool, but every single other person in this thread saw it with Prolog in their third year of uni, so we don't feel the need to extol the virtues of a programming paradigm that isn't news to us.

And it is a lot more neat in prolog than it is in erlang:


append([],X,X). % appending a list to an empty list is the same list.
append([H|T],L,[H|O]) :- append(T,L,O). % appending a list to a list, is appending the head of a list to the output, where the output is the result of appending the tail of the list to the other list.


Then you can use append to get the last element from a list:

:- append(_,[X],[1,2,3,4]).
X = 4?

Zombywuf
Mar 29, 2008

MononcQc posted:

I have never heard of anyone associating discriminated unions and Erlang. I don't know, I've always heard of the term used with languages supporting ML-like type systems. Where is this coming from?

Pattern matching is a generalisation of discriminated unions. Think what you get with algebraic data types and then remove static typing.

Zombywuf
Mar 29, 2008

tef posted:

And it is a lot more neat in prolog than it is in erlang:

*ahem*
code:
factorial(0, 1).
factorial(N, N * FF) :-
    factorial(N - 1, FF).

ColdPie
Jun 9, 2006

Should've known the 65 new posts weren't 65 new funny posts but instead 65 new posts arguing about functional programming.

zootm
Aug 8, 2006

We used to be better friends.

Zombywuf posted:

If you think that:
  • Have never heard of multi-agent ontology oriented programming
This does not make sense.

Also Actor/Agent/Process model is basically just asynchronous object-orientation. Message-passing actors are a really nice way of building but sometimes people act as though they're some kind of magic cure-all when they're not really all that different to how large systems were already engineered. Erlang's "big win" is nicely codifying and implementing the frameworks you need to get this sort of thing off the ground.

Don't know where I'm going with this. In any case these arguments seem secondary to the stated goal of coding horrors.

Edit:

ColdPie posted:

Should've known the 65 new posts weren't 65 new funny posts but instead 65 new posts arguing about functional programming.
Most of the time I just hear a fine hiss.

shrughes
Oct 11, 2008

(call/cc call/cc)

ColdPie posted:

Should've known the 65 new posts weren't 65 new funny posts but instead 65 new posts arguing about functional programming.

You mean 66.

Edit: 68.

Zombywuf
Mar 29, 2008

ColdPie posted:

Should've known the 65 new posts weren't 65 new funny posts but instead 65 new posts arguing about functional programming.

And one post whinging about people arguing about functional programming.

zootm
Aug 8, 2006

We used to be better friends.

Zombywuf posted:

And one post whinging about people arguing about functional programming.
Sometimes a thread needs a good meta-whinge so it can get back on track.

Zombywuf
Mar 29, 2008

zootm posted:

Sometimes a thread needs a good meta-whinge so it can get back on track.

I hate meta-whinging.

MononcQc
May 29, 2007

Zombywuf posted:

Pattern matching is a generalisation of discriminated unions. Think what you get with algebraic data types and then remove static typing.

Oh alright. That makes sense then. know of any other language that has the supervision trees, by the way? (I'm asking out of sheer curiosity)

To actually contribute to this thread, I just stripped our website's code base from a bunch of

php:
<?
if (!defined('LISTS_PHP_')) {
    define('LISTS_PHP_','1');

    // Some class declaration here

} // defined
?>
This kind of stuff was used in every god drat library file we had because at some point in history the site would have some kind of common library directory with a bunch of other sites we had on a single server. Said websites would sometimes call files coming from each other to allow some weird interactions.

As a result, the same lib would be check-outed 2-3 times on the same metal in different directories and when the sites would cross-include files, you'd get circular dependencies and class name clashes because PHP includes rely on the filename and path, not on the contents. The solution the old team found was to define constants on each file include to avoid the PHP interpreter making GBS threads itself.

It was a loving nightmare. Took our team over a year to move poo poo out to different VMs, get rid of all the circular dependencies, kill the hard-coded poo poo and whatnot. There's still a lot of work to do too :(

Zombywuf
Mar 29, 2008

MononcQc posted:

Oh alright. That makes sense then. know of any other language that has the supervision trees, by the way? (I'm asking out of sheer curiosity)

The only places I've seen anything similar are server/daemon monitoring tools. Erlang is the only place I've seen it as part of the language, this is another area where Erlang seems to be trying to subsume the UNIX philosophy.

zootm
Aug 8, 2006

We used to be better friends.

MononcQc posted:

This kind of stuff was used in every god drat library file we had because at some point in history the site would have some kind of common library directory with a bunch of other sites we had on a single server. Said websites would sometimes call files coming from each other to allow some weird interactions.
Is the resemblance to C headers deliberate or did they arrive at the same solution independently? That's pretty horrifying though.

Zombywuf posted:

The only places I've seen anything similar are server/daemon monitoring tools. Erlang is the only place I've seen it as part of the language, this is another area where Erlang seems to be trying to subsume the UNIX philosophy.
It's actually technically part of the OTP library rather than the language, and (like quite a lot of the stuff in OTP) is something that appears missing in a lot of other languages' implementations of the actor model (I've seen it in Akka but it doesn't appear that that many people understand how important this aspect is). Erlang's library really is its interesting aspect.

MononcQc
May 29, 2007

zootm posted:

Is the resemblance to C headers deliberate or did they arrive at the same solution independently? That's pretty horrifying though.
One of the lead devs back then (years before I got here) was a C programmer down to the bone. Never bothered to get into PHP the way he should have (not that I can blame him).

He was also a huge fan of one-letter variables, uncommented code, monitoring through private shell scripts on his own workstation and apparently would walk around the office with a katana.

Zombywuf posted:

The only places I've seen anything similar are server/daemon monitoring tools. Erlang is the only place I've seen it as part of the language, this is another area where Erlang seems to be trying to subsume the UNIX philosophy.

I always liked etop as another example of following the UNIX concepts, except it can monitor remote nodes too.

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

MononcQc posted:

One of the lead devs back then (years before I got here) was a C programmer down to the bone. Never bothered to get into PHP the way he should have (not that I can blame him).

The proper way to get into PHP is in a casket

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Mustach posted:

Is this a "lol they suck?"
No, no,. the names of the lexer and parser amused me, is all :)

wrok
Mar 24, 2006

by angerbotSD

Dijkstracula posted:

But you're loving kidding yourself if you try and correlate a language's "quality" with a self-serving "you must be this smart to enter" metric. And further, you can't compare the "average quality" of code of a language that isn't used in a production setting, with one that is. If Java wasn't used by every half-assed developer and his dog to slap together some lovely business app, then you too could probably look at the average piece of Java code and say, "yes, this is beautifully written."

:hfive:

Language generalizations are for people that don't write code.

(Though gently caress VB/ASP right in the rear end, srs).

PT6A posted:

Getting back to the point about functional languages, I think people who've used them to some degree write better code because it's such a mindfuck when you first get started that you have to really understand what's going on, within the code, and within whatever code you're trying to write.

That's bullshit. They're only a mindfuck because you're* coming from a whole lifetime of being drilled with procedural stuff. If you did not grok programming at all you'd probably find functional stuff MUCH more welcoming, logical and sensical than 'traditional' procedural programming.

(* = impersonal you, we, etc.)

wrok fucked around with this message at 02:10 on Dec 1, 2009

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

wrok posted:

That's bullshit. They're only a mindfuck because you're* coming from a whole lifetime of being drilled with procedural stuff. If you did not grok programming at all you'd probably find functional stuff MUCH more welcoming, logical and sensical than 'traditional' procedural programming.

As someone who's first real introduction to programming was declarative and functional, I'll stand by this statement here. I still don't really understand why anyone would ever choose to use object-oriented programming unless it's all they know or they were somehow forced to, but I've learned this isn't an argument I'm likely to win.

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane

wrok posted:

That's bullshit. They're only a mindfuck because you're* coming from a whole lifetime of being drilled with procedural stuff. If you did not grok programming at all you'd probably find functional stuff MUCH more welcoming, logical and sensical than 'traditional' procedural programming.

(* = impersonal you, we, etc.)

That's actually very true, I never thought of it that way.

Of course, if you come from functional programming, something like OO will be just as foreign when you start. Perhaps the mark of a good programmer is being able to comprehend and utilize multiple paradigms effectively, no matter where you started.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

PT6A posted:

Perhaps the mark of a good programmer is being able to comprehend and utilize multiple paradigms effectively, no matter where you started.

"Perhaps?" I thought this was an obvious truism.

Adbot
ADBOT LOVES YOU

Opinion Haver
Apr 9, 2007



I can't wait to use the 'seeking feed fwd', the 'anonymous role mixin', and the 'hyper dwim all'!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply