Open Side Menu Go to the Top
Register
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

01-10-2013 , 04:16 AM
Quote:
Originally Posted by tyler_cracker
dave,

1. you'll have to work pretty hard to get the *compiler* to fail while compiling your code.

2. for understanding deep compiler behavior, there are few tools as useful as reading the generated assembly.
Sorry, I didn't mean I want to destroy my compiler. I simply wanted my compiler to tell me to tell me to **** myself and not produce anything new. This is what happens when I forget to put a ; somewhere. The whole program just doesn't compile. I was wondering why the compiler was willing to accept this new stuff. Maybe because it doesn't pre-compile, run the program for me, and tell me that I don't have enough memory or something. Eh, this is all too far afield for now.


Quote:
Originally Posted by candybar
A language that ranks too high in prestige/snob-appeal/idealism relative to its real-world usefulness is going to attract too many people who want to use it to feel better about themselves and cherish their minority status, as opposed to people who want to get things done. This leads to an ecosystem that is oriented towards maintaining its prestige, as opposed to being useful to allow everyone else to get things done. This is a bit unfair, because there are tons of Lisp programmers who don't fit this description, but Lisp in particular has a history of attracting uncompromising idealists, language snobs and others of elitist mindset.

Expressiveness matters for adoption and productivity but abstract cleanness and nonbrokenness of the language that purists care about usually only become relevant for extremely large applications which these clean languages ultimately never get used for, in part because the community refuses to compromise.
This I agree with. The chicken-egg problem, at least from what I've seen in some conversations is something like:

"Only the top N% of all programmers can use Lisp well, but there is no way to know you are a top N% until you try"

Then the opposite argument goes:

"Lisp makes you a top N% programmer, you have to force yourself to try it out, but you need to stick with it."

I'm nowhere near a top N% < 90% programmer and this is the biggest issue with all of this stuff. People grab onto stupid minor things and then conflate those issues into large road-blocks, and that perpetuates the mythos surrounding Lisp / Haskell / OCaml / ETC.

Of course it doesn't help that there is the whole "do it yourself" attitude surrounding Lisp / Clojure. The refusal to upkeep or acknowledge frameworks keeps people from having a chance to explore the languages. I get the idea is that it isn't for the feint-of-heart, but I really don't think that Lisp is the "hacker's language" people trumpet it to be. Sure, some people are perfectly comfortable staring at nothing and creating something from it, but I don't buy the argument that all good programmers prefer to work this way, and I most certainly don't buy that bad programmers are those that don't want to work outside of frameworks and some pre-fab stuff. There is a lot to be said about no reinventing the wheel, though I don't think that I ever did anything in Lisp that is reinventing wheels.

Quote:
Originally Posted by sdturner02
Strong observations from both of you.

This is precisely what I was alluding to with my "boys club" question. It's also one of the reasons that I like the 2p2 Programming forum -- an eclectic mix of backgrounds keeps this in check.

The issue seems somewhat analogous to inbreeding, or perhaps water stagnation. It's a problem that perpetuates itself because it needs outside influence to improve, and yet the greatest effect of the problem is that it repels outsiders.

Maybe this is how programming languages die?
Could be... I think that what kills programming languages is the desire to answer a few questions:

"Can I use this at work?" -- Will Mr Pointy-hair approve of this new language? Clojure gets it right because its on a JVM but gets it wrong because its a Lisp. I bet Scala will become more corporate and probably more popular in the long run. The irony is that Clojure opened up the FP conversation and allowed Scala to gain it's initial traction.

"What can I build with this that is unique?" -- RoR allows you to build large websites. Wordpress has blogs.

"How easy is it to get started?" -- Clojure fails miserably in this regard. Lisp is a heck of a lot easier, but there isn't anything to give you that extra boost, like simple frameworks and then deploying it is nearly impossible. Heroku helps Clojure a bit here, but that's the end, not the beginning. Hell, my old shared hosting had WordPress and RoR. I'm led to understand the Scala isn't very easy to start with either.

"How familiar is it with X" -- X can be OOP, Brackets, Variable creation, and a whole slew of items. Lisp is just too damn weird for people.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 07:13 AM
I'm not even sure I can explain what I meant...
Basically I have some CD title displayed in a browser window
Then someone comes along and changes it
How does some other person viewing the page know which "version" to see

Basically if we start with cd_title = "ABCD" then an update is made we have say cd_title_2 = "AAAA" and ever onward. The old cd_title will still be there. How is this handled, is there just some sort of pointer to "most current cd_title"?
If I understand FP correctly there isn't even a cd_title_2 because there's only the original cd_title and a chain of operations done on it.
Is the original state and all operations done to it stored? Are timestamps used?

I'm envisioning this as similar to garbage collection in practice i.e. after X time units the state is actually changed.

*off to read about monads*
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 07:47 AM
Here's a youtube video where Chaz Emerick gives a walk through of creating a webpage that is url shortener, which sounds pretty close to what you are talking about. Click up to 40 minutes and adjust to get to walk-through:

http://www.youtube.com/watch?v=VVd4ow-ZcX0

I haven't watched the video since it is what is in his book, but at least in the book, he uses an atom (a mutable value-type), which is used to create new id's and the map is also mutable and he also uses some functions like swap!. The "!" indicated mutation in Lisp. So, if your asking "Is it possible to create an immutable mapping in this example?" the answer is "Yes, but why would you?" This is clearly a case where mutation is superior, and I would hope someone would decide that a database would be the wise choice in a deployed application.

In regard to your specific example, you'd probably have something like this (in python):

cds = {}

cds[title] = now()

then you can grab the key with the largest time-value and display it in a route (in Clojure now).

(defroutes
(GET "/:cd-name" (max-cd-date))

cds = {:cd-name now()} <--- Send this as an argument to defroutes.

I'm sacrificing accuracy here in favor of clarity:

:cd-name is the rest of the URL. The (max-cd-date) is completely wrong here, but basically you'd push the dictionary into the defroutes function and then destructure the dictionary to what you want to display to the user.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 08:11 AM
So would it be fair to say...

Basically the "no shared mutable state in functional programming, everybody's solid" is pretty much a myth in many practical cases?
Atoms exist in Clojure, actors in Erlang etc.

But in essence these languages are still "better" at multicore stuff because they (try to) default to non-mutable state while typical OO languages default to mutable state?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 09:19 AM
Quote:
Originally Posted by clowntable
So would it be fair to say...

Basically the "no shared mutable state in functional programming, everybody's solid" is pretty much a myth in many practical cases?
Atoms exist in Clojure, actors in Erlang etc.

But in essence these languages are still "better" at multicore stuff because they (try to) default to non-mutable state while typical OO languages default to mutable state?
Here's an overview:

http://www.ibm.com/developerworks/ja...183/index.html

Also note that multicore != concurrency. There is a subtle but important difference here and the conversation is around concurrency more than multicore programming.

Yes, you can use atoms, set! and other stuff, but its not supposed to be used with abandon, which I've seen many IP programmers post FP code on SO doing. I'm not sophisticated enough to really know of a particular situation where using these constructs are better than using immutable values.

You did ask specifically about querying a database or building your own database, and yeah, the databases I am familiar with are mutable by definition (except maybe Datomic). The unfortunate part of the video I posted is that, in this case, the database is a leaky abstraction and that forced the program to take on many mutable issues, and that is, in my opinion, very bad form. I understand that he doesn't have time to show the set up of a database, a DSL, and routing over data extracted from a database, but if he had a database + DSL set up, the visible program would have no mutation at all, so in essence, you sort of asked a trick question: databases, at least in the way they are commonly used, are mutable, thus any program we write that use these databases will have some mutation in them, however this does not mean that the code (written in Erlang, Clojure, Haskell, etc) has to use mutation to interact with the mutating database.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 09:59 AM
Quote:
Originally Posted by Neil S
The example may work better if you use dynamically allocated memory.

Code:
#include <stdio.h>
int main(int c, char **v)
{
    /* Stinking inability to use tab in this box */
    const int length = 4;
    char *string = malloc(length);
    for(int i = 0; i < length; ++i)
    {
        string[i] = 'a';
    }
    printf("String: '%s'\n", string);
    return 0;
}
I was almost hoping to see a flash of light and Linux flip upside down or something. Instead I get:

$ make wtf
cc -Wall -g wtf.c -o wtf
wtf.c: In function ‘main’:
wtf.c:6:5: warning: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration]
wtf.c:6:20: warning: incompatible implicit declaration of built-in function ‘malloc’ [enabled by default]
wtf.c:7:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
wtf.c:7:5: note: use option -std=c99 or -std=gnu99 to compile your code
make: *** [wtf] Error 1

the options won't let me do anything. Oh well, learning about if statements is probably more important than this.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 10:09 AM
Heh, clearly Apple's compiler (clang on LLVM) defaults to a different C than yours.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 10:18 AM
I swear that "no declaring variables in for loops" thing comes up every damn time I try to write C code
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 10:21 AM
Quote:
Originally Posted by daveT
Hey, xhad. Code Academy is not on the front page of HN and everyone is talking up how great they are.
To be fair, I actually think the site is overall good. I mean, I've done 80% of the code year track and you guys have seen more than half the serious problems I've come across. It's just that the bad stuff I've seen strikes me as really bad and they don't seem to be very good about accepting feedback when that happens.

I mean, when they have an exercise along the lines of "write a game," get the rules wrong, and have had message board posts telling them it's wrong for over six months and can't even be bothered to update the instructions...
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 10:33 AM
Quote:
Originally Posted by Xhad
I swear that "no declaring variables in for loops" thing comes up every damn time I try to write C code
Which is odd since c99 is now, well, over a decade old.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 10:42 AM
Quote:
Originally Posted by Neil S
Heh, clearly Apple's compiler (clang on LLVM) defaults to a different C than yours.
How do you figure?

malloc() is part of the stdlib, not stdio. You forgot to include that header file.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 10:50 AM
Quote:
Originally Posted by Shoe Lace
How do you figure?

malloc() is part of the stdlib, not stdio. You forgot to include that header file.
Um, that's not why it errored out. Read it again.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 10:57 AM
I got the errors to pop. Nice one, Niel S. I'm not going to post it here, but I have now witnessed the abyss.

Shoe, I stupidly attempted to run

$ make -std=c99 wtf

when I was supposed to do

$cc -std=c99 wtf.

I could change my makefile to default to c99 if I want to, but I guess it's in -Wall right now. Interesting stuff.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 11:17 AM
I never used whatever Dave is using to compile stuff but if I try to compile that with clang it cries because stdlib.h isn't included which seems like normal behavior to me because malloc() is a stdlib function.

Compiled with:
Code:
clang -ggdb3 -O0 -std=c99 -Wall -Werror    foo.c  -lm -o foo
Error:
Code:
foo.c:6:20: error: implicitly declaring C library function 'malloc' with type 'void *(unsigned int)' [-Werror]
    char *string = malloc(length);
                   ^
foo.c:6:20: note: please include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
Look at the note from the error.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 11:58 AM
Why are you using -Wall -Werror for a quick little test on a forum?

The default C signature for malloc works fine in this context, which is why I didn't bother with the header.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 12:14 PM
I guess what I'm wondering is...is there even something like a pure functional "database"? I guess it would require storing something like the base data and all operations on it with a timestamp or something?

Can't even comprehend how such a thing is supposed to work.

I also don't quite get how randomness is supposed to worl. I guess you can only have random number streams but you'll always know how input->output?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 12:15 PM
I'm using gcc which comes pre-installed with Arch Linux. Apparently it also comes with Valgrind.

And why aren't you using a makefile so you don't have to type all that junk out every time?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 12:31 PM
Quote:
Originally Posted by clowntable
I guess what I'm wondering is...is there even something like a pure functional "database"? I guess it would require storing something like the base data and all operations on it with a timestamp or something?

Can't even comprehend how such a thing is supposed to work.

I also don't quite get how randomness is supposed to worl. I guess you can only have random number streams but you'll always know how input->output?
I just read part of the Datomic website. It appears that they use immutability on the assumption that memory is cheap and aplenty. Apparently, this model starts to fall apart once you have fast read/write considerations and extremely large data-sets since memory isn't unlimited.

I don't see how a smaller database can't be non-destructive with sophisticated time-stamping. Obviously there's some mutation as you add, but you can't ever subtract.

How would randomness work? As I understand it, if you put 7 as the arg to a RNG, you are going to pull out the same number all the time. At least that's how it worked when I tried a raw single-arg RNG algorithm that I copy / pasted into scheme from some website. You can add in other variables to make is more "random," like computer time, etc, but I don't consider randomness non-fuctional at all.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 12:37 PM
Quote:
Why are you using -Wall -Werror for a quick little test on a forum?
I always use -Wall and -Werror. If you're going to have a compiler compile code for you, you might as well have it set to be useful and catch as many potential issues as possible.

Quote:
And why aren't you using a makefile so you don't have to type all that junk out every time?
It is in a make file, all I had to do is type "make foo" in this case.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 12:53 PM
Quote:
Originally Posted by Shoe Lace
I always use -Wall and -Werror. If you're going to have a compiler compile code for you, you might as well have it set to be useful and catch as many potential issues as possible.



It is in a make file, all I had to do is type "make foo" in this case.
We disagree on whether turning warnings in to errors is useful then, considering warnings are made warnings, and not errors, for a reason. They're not actually *wrong*.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 01:00 PM
Def +1 on -Wall and I also refactor the code to not have any more warnings unless I have a very specific reason and know why I need that part of the code.
Usually it's just a coding error of sorts on my part (I'm surprised that there is a warning).

They exist for a reason.

Edit: Also I don't think I have fully grasped monads yet. The space suit analogy is pretty good but I'll come back to it tomorrow and mindmap the concept or something to make sure I fully understand it.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 01:17 PM
Quote:
Originally Posted by clowntable
Edit: Also I don't think I have fully grasped monads yet. The space suit analogy is pretty good but I'll come back to it tomorrow and mindmap the concept or something to make sure I fully understand it.
Practically no one fully understands the concept of monads, so don't feel bad if it takes some time to become familiar.

It helps if you think of the problem as, how do we abstract state away from our program so that all expressions in our program are pure expressions that can be evaluated in whatever order you like, as many times as you like without impacting the behavior of the program, not how do we avoid state in the real world.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 01:36 PM
Quote:
Originally Posted by Neil S
We disagree on whether turning warnings in to errors is useful then, considering warnings are made warnings, and not errors, for a reason. They're not actually *wrong*.
I see warnings as potential issues and fixable problems. Just because it compiles doesn't mean it's right. If the compiler feels like it's necessary to report something then it's likely for good reason. No news is good news IMO.

I wish I were a full time C developer. I would be the guy who enforces 0 warnings, 0 leaks and all code to pass 2 static code analyzers before shipping. You would be locked in a cage without food or drink until the code you commit passes those standards.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 01:42 PM
IT PUTS THE MALLOC IN THE BASKET.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2013 , 01:42 PM
Quote:
Originally Posted by candybar
Practically no one fully understands the concept of monads, so don't feel bad if it takes some time to become familiar.
Bob Martin's video "WTF is a monad" is very good. You can find it here: http://blog.redmuffin.de/robert-c-un...o-resources-on
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote

      
m