The Artima Developer Community
Sponsored Link

Java Community News
Threads Considered Harmful

42 replies on 3 pages. Most recent reply: Feb 1, 2007 6:00 AM by James Watson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 42 replies on 3 pages [ « | 1 2 3 ]
Cameron Purdy

Posts: 186
Nickname: cpurdy
Registered: Dec, 2004

Re: Idempotent operations Posted: Jan 28, 2007 2:37 PM
Reply to this message Reply
Advertisement
Gregor,

> Isn't an idempotent method the same as a const method
> where all parameters are const? That would be easy to
> verify.
> Or is there an additional requirement that the method
> doesn't perform IO?

Idempotency refers to the ability to call the method once, twice, or any number of times (greater than one) and to have the same set of side-effects in total regardless of how many times the method is called.

This is supposed to hold true even in the case of exceptional conditions. For example, in a server cluster, if you execute the method once and the server running it dies half way through, then you should be able to re-execute the method on a different server and have the end result of the system be the same as if the first server finished it completely and no one else ran it.

I continue to promote the idempotent style of architecutre. For distributed systems, idempotency is one of the only silver bullets available.

Peace,

Cameron Purdy
http://www.tangosol.com/

Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: Threads Considered Harmful Posted: Jan 29, 2007 4:19 AM
Reply to this message Reply
> James Watson wrote I'm not sure why you would represent
> this as being some sort of crazy idea.

> I'm not sure why you would represent what I wrote as
> though I was saying Frank Silbermann's comments were a
> crazy idea.
>
> James Watson wrote It's clearly one of the commonly
> held tenets ...

> James, I provided an example of "a multiuser Distributed
> DBMS" written in what is generally regarded as a
> functional programming language.
>
> Please provide some example programming language that
> corresponds to your notion of a functional programming
> language.
>
> I think it's possible that your notion of functional
> programming and Frank Silbermann's notion of functional
> programmming don't correspond to any language used by the
> functional programming community.

I have to agree with James Watson on this: while FP certainly has its benefits, its oversold. Most non trivial non academic programs do heavy use of the IO monad, so they are not subject to parallelization.

The real advantage of FP languages and not FP is their type systems, which can prevent lots of accidental errors. For example, mainstream imperative programming languages allow the free use of 'null' as a pointer value, whereas FP languages prohibit the use of 'null' and only allow it as 'nil' in an algebraic type, forcing the programmers to write code for handling the case of 'nil'. But algebraic types could be applied to imperative programming languages as well.

The automatic parallelization of pure programs (i.e. programs without assignment) contains a very big obstacle: how to allocate computational units at run-time so as that the parallel computation is optimal? in order to parallelize a pure algorithm, a scheduling algorithm has to know which computational unit is free, has to assign the next available computation to the unit etc. This can not be done easily, and the overhead may be so great that all the program actually does is schedule the computations.

Another problem is when data must be created. In a parallel program, creation of list cells means that a memory block is allocated from the garbage-collected heap. This means the allocation should be protected by a critical section because the memory manager's data are global. Not only that, but the scheduler must actually wait for the allocator to finish before taking the address of the allocated block and pass it to another computation. Take, for example, the standard quicksort algorithm:


sort h:t = (less (sort h t)) : h : (greater (sort h t))
| [] = []


The above algorithm, although it takes two lines to express, can not be parallelized: the expression h : (greater (sort h t)) means that the scheduler must wait for (greater (sort h t)) to finish before passing the result to the cons operator...which in turn must be consed with (less (sort h t)). During the allocation operation, the garbage collector must be locked.

The quicksort algorithm could be parallelized if the size of the list was known. For example, if we had N elements in the list and M threads, we can use N/M elements per thread. But the size of a linked list is not known in functional programming languages, and the number of threads allocated to the algorithm can only be determined at run-time.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Threads Considered Harmful Posted: Jan 29, 2007 6:14 AM
Reply to this message Reply
> James Watson wrote I never said there were any horrors.
> It seems like you have to run around the block to get next
> door to deal with state in functional languages but I
> don't think it's horrible.

>
> LOL!
>
> So why have you been making a fuss about my objection to
> Frank Silbermann's throwaway "Just imagine the horrors..."
> comment?

You call that a fuss?

You seemed to be implying that there was no special handling required for working with state in functional languages. His comment was probably misguided at least to some degree but I think at the core there's something to the idea it came from or at the very least a perception that that is the case. I didn't find your response very informative. Instead of explaining how state is dealt with in functional languages or offering some references, you basically just said 'you're wrong'.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Threads Considered Harmful Posted: Jan 29, 2007 6:23 AM
Reply to this message Reply
> I have to agree with James Watson on this: while FP
> certainly has its benefits, its oversold. Most non trivial
> non academic programs do heavy use of the IO monad, so
> they are not subject to parallelization.

I'll just make my stance exactly clear. I think that functional approaches offer great advantages to imperative approaches in a lot of cases, usually the exact cases that are problematic in imperative approaches (e.g. resource management.)

What I don't agree with is this dogmatic idea that all programs should be written with 100% functional approaches. It's just a foolish as the dogmatic idea that programs should be written with 100% imperative approaches.

Isaac Gouy

Posts: 527
Nickname: igouy
Registered: Jul, 2003

Re: Threads Considered Harmful Posted: Jan 30, 2007 11:00 AM
Reply to this message Reply
James Watson wrote

> > Frank Silbermann's throwaway "Just imagine the
> > horrors..." comment?
>
> You call that a fuss?

I call it fuss about nothing.


> You seemed to be implying that there was no special
> handling required for working with state in functional
> languages. His comment was probably misguided at least to
> some degree but I think at the core there's something to
> the idea it came from or at the very least a perception
> that that is the case. I didn't find your response very
> informative. Instead of explaining how state is dealt
> with in functional languages or offering some references,
> you basically just said 'you're wrong'.

No, basically I said - his comment was FUD - it didn't aspire to being right or wrong.

(Instead of explaining how state is dealt with in functional languages or offering some references, he basically just said "it's horrible")

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Threads Considered Harmful Posted: Jan 30, 2007 12:20 PM
Reply to this message Reply
> No, basically I said - his comment was FUD - it didn't
> aspire to being right or wrong.
>
> (Instead of explaining how state is dealt with in
> functional languages or offering some references, he
> basically just said "it's horrible")

Well I guess you are in good company.

Isaac Gouy

Posts: 527
Nickname: igouy
Registered: Jul, 2003

Re: Threads Considered Harmful Posted: Jan 30, 2007 10:38 PM
Reply to this message Reply
What can be asserted without evidence can also be dismissed without evidence.

Cameron Purdy

Posts: 186
Nickname: cpurdy
Registered: Dec, 2004

Re: Threads Considered Harmful Posted: Jan 31, 2007 5:26 AM
Reply to this message Reply
What can be evidenced without assertion can also be evidenced without dismissal.

"Get your facts first, and then you can distort them as much as you please." - Mark Twain

;-)

Peace,

Cameron Purdy
http://www.tangosol.com/

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Threads Considered Harmful Posted: Jan 31, 2007 6:27 AM
Reply to this message Reply
> What can be asserted without evidence can also be
> dismissed without evidence.

"Strychnine" a short play by James Watson:

[Frank] Drinking strychnine is bad for you health.

[Isaac] Where's your evidence? Snake handlers' drink strychnine all the time. I have a video right here.

[Frank] You got me. Here's your glass.

[Isaac] Thanks.

Isaac Gouy

Posts: 527
Nickname: igouy
Registered: Jul, 2003

Re: Threads Considered Harmful Posted: Jan 31, 2007 8:05 PM
Reply to this message Reply
Cameron Purdy wrote some tangled sentence, but included a funny Mark Twain quote.

However, Mark Twain's words only stand as a reminder that facts may not be sufficient (just as wearing a seatbelt may not be sufficient to save us in an accident)

Mark Twain's words are not an argument that it is better not to refer to facts (just as the insufficiency of seatbelts is not an argument that is better not to wear a seatbelt).

Isaac Gouy

Posts: 527
Nickname: igouy
Registered: Jul, 2003

Re: Threads Considered Harmful Posted: Jan 31, 2007 8:09 PM
Reply to this message Reply
James, I think you should stand behind your own words instead of dragging in Frank.

Cameron Purdy

Posts: 186
Nickname: cpurdy
Registered: Dec, 2004

Re: Threads Considered Harmful Posted: Feb 1, 2007 4:23 AM
Reply to this message Reply
> Cameron Purdy wrote some tangled sentence, but included a
> funny Mark Twain quote.

Just trying to point out that you guys are getting a bit too serious (borderline personal).

Respectful disagreement and debate are great learning tools. Otherwise, things degrade:

http://carcino.gen.nz/images/index.php/00b9a680/463c5922

Peace.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Threads Considered Harmful Posted: Feb 1, 2007 6:00 AM
Reply to this message Reply
> James, I think you should stand behind your own words
> instead of dragging in Frank.

These were names pulled out of thin air. I don't know where you got the idea they were meant to represent actual people.

Flat View: This topic has 42 replies on 3 pages [ « | 1  2  3 ]
Topic: Firebug Creator Joe Hewitt's Yahoo YUI Video Previous Topic   Next Topic Topic: Neal Gafter on a Definition of Closures

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use