« first day (633 days earlier)      last day (4315 days later) » 

9:04 PM
This is a good book btw, if you like science fiction.
http://www.amazon.com/Lost-Gate-Mithermages-Library/dp/1441771638
 
user1174868
If I wasn't so stupid I might be better at programming
 
0
Q: Why a static main method in Java and C#, rather than a constructor?

Konrad RudolphWhy did (notably) Java and C# decide to have a static method as their entry point – rather than representing an application instance by an instance of an Application class, with the entry point being an appropriate constructor which, at least to me, seems more natural? This has been asked before...

Let’s see how this turns out
 
Java did this because Java's creator is dumb, and C# did that because Java did that.
With some C/C++ envy thrown in (they've got functions and we kinda forgot to do that QQ, let's use static method).
Haha, someone downvoted.
 
user1174868
just like reddit
 
@CatPlusPlus, awesome picture and name.
 
9:08 PM
@KonradRudolph I'm far from an expert but it sounds a lot like some things I see asked on PSE.
 
I can't help but to smile everytime I see that cat
 
@RMartinhoFernandes Ah fuck me
 
I'm telling you, this happened like I said.
@jmlopez Cool.
 
@RMartinhoFernandes move?
 
Xeo
@RMartinhoFernandes And it doesn't seem like something that belongs on PSE
 
9:10 PM
@KonradRudolph For some reason I can't move there.
@Xeo Why not? Want me to bring up similar examples?
4
Q: Why does F# have an interactive mode but not C#?

George MauerF# comes out of the box with an interactive REPL. C# has nothing of the sort and is in fact kinda difficult to play around without setting up a full project (though LINQpad works and its also possible to do via powershell). Is there something fundamentally different about the languages that allo...

From the front page.
 
@RMartinhoFernandes Yes, apparently disabled. I flagged it.
 
Xeo
Maybe I'm missing the point of PSE, but wasn't it about the programmer and not about coding per-se / the languages?
 
Nobody knows what it's for.
 
Dunno what sticks they use to measure it. All I know is what I see there.
 
They just randomly shuffle threads back and forth.
But shhh, it's a secret.
 
user1174868
9:12 PM
Why the hell does every recursion example always start with factorial? It is the most useless recursion example
 
Because it's simple.
 
bah, almost closed as “not constructive” … sometimes I despair
 
user1174868
It teaches you nothing about recursion except that factorial is perfectly built for it
 
It has a clear terminating condition.
 
9:13 PM
then again, I fear that they are simply right and there’s no reason behind this at all
 
What's there to teach about recursion?
 
Recursion is just function calling itself. What do you expect from the example?
 
user1174868
Exactly, but you can't take that information and apply it to anything else other than factorial pretty much
 
What.
 
user1174868
How recursion can work with two variables
 
9:13 PM
@DesmondHume Well, well. I think that's why most people who try to get a degree in CS drop out before the end.
 
Applying recursion to things that aren't naturally recursion is objectively stupid.
 
If they shown you recursive tree traversal, you'd know better how to apply it to things that are not tree traversal?
 
So, factorial seems to make perfect sense.
 
user1174868
I don't even know that tree traversal means
 
Xeo
Maybe we need a meta thread like "What is PSE actually about?"
 
9:14 PM
Plus there's that whole "tail recursion is equivalent to a loop".
 
@Xeo Nobody there seems to know ;p
 
If I show you a simple tail recursive function as an example of that, you'd just go "it's too simple", or what?
I really don't get the point here.
 
@Jordan no, but it's simple. If you go straight to real usages, nobody would understand them.
 
“ask in the MSDN forums” – now that is a helpful answer (not sarcasm!), at least it won’t be closed there
 
user1174868
I am not asking for homework help
 
9:16 PM
(As demonstrated by "I don't even know what tree traversal is".)
 
Hey guys. Sorry to bother you with such a simple question that I've found on google many many times... but, is something like double *p = new (std::nothrow) double[HUGENUMBER GOES HERE] supposed to set p to NULL if it cannot allocate enough memory?
 
user1174868
I think I need a disclaimer on all my messages
 
@jmlopez yes
 
@Jordan Not the point.
 
user1174868
I feel like this is a trap
 
9:17 PM
Simple example shows you what matters the most — which is recursion here.
 
@MooingDuck, is my program supposed to crash?
 
user1174868
and I will get banned from chat
 
I get: malloc: *** mmap(size=18446744067890511872) failed (error code=12)
 
It skips unimportant details that crop up in real recursive things for the sake of explaining core concept first.
Which is just that — calling itself.
 
@Jordan That's not true. Many uses for recursion in the real world.
 
user1174868
9:18 PM
I like that but I wish they would build off that example and do one slightly more complex, and then another one slightly more complex than that
 
user1174868
Like math books, they build up, it seems programming doesn't really do that
 
Just like your first tail recursion example will be "this is a loop that counts to 10, and this is how you express that as tail recursion".
What.
 
@Jordan Sounds like you simply got stuck with terrible material.
 
user1174868
I think everyone likes SICP here
 
@Jordan, have you done the Sierpinski triangle example? en.wikipedia.org/wiki/Sierpinski_triangle
 
9:19 PM
For the past two minutes I've been saying how it does build up.
 
user1174868
@jmlopez No but it looks like the square pattern one
 
@jmlopez no
 
I'm pretty sure SICP has some tree traversal as a more involved recursion example.
 
@Jordan quicksort is usually the next complexity of examples
 
9:20 PM
Or maybe quick sort.
 
I love fractals... the Mandelbrot and Julia sets are absolutely beautiful.
 
Quick sort is shitty, though.
 
user1174868
I don't know lists yet
 
@CatPlusPlus irrelevant
 
@MooingDuck I mean implementation-wise.
 
9:20 PM
@MooingDuck Quicksort is actually quite tricky. I don't think I've ever (correctly) implemented one. (not that I've tried very hard)
 
@KonradRudolph Sweet.
 
Tree traversal is better to show off recursion.
 
@Jordan so you're upset that the basic building block is useless despite the fact haven't yet learned anything you can use that block for?
 
And more useful than implementing QS without all the quirks that make it actually usable.
 
oh why is the bool default value random :(
 
9:21 PM
Because you're using uninitialised variables, which is UB.
 
qsort [] = []
qsort (x:xs) = [l | l <- xs, l <= x] ++ [x] ++ [r | r <- xs, r > x]
@Mysticial See, it's easy.
 
so Automaton's are essentially a kind of state machine?
 
user1174868
@MooingDuck I am upset that all I really learned from the example is how to do the example. I can't seem to apply it to anything more complex
 
@RMartinhoFernandes What language is that?
 
Xeo
@RMartinhoFernandes That's the most suboptimal version ever, wasn't it?
 
9:22 PM
@TonyTheLion Automatons are people too!
 
Xeo
@Mysticial Haskell
 
Haskell
 
@Xeo Well, turns out, no.
GHC optimizes the heck out of it.
And I mean it.
 
Shit that's short...
 
++ is concat operator right?
 
Xeo
9:22 PM
yea
 
@CatPlusPlus Can I set it to false during definition? Or do I have to loop and set false?
 
@Jordan you can, you just haven't yet
 
user1174868
whatever I give up, I am just going to ask my question somewhere in the internet, I can't do this on my own
 
@Xeo It humiliated me against my hand-made version with mutable arrays.
 
@ManofOneWay Use the damn vector already.
 
Xeo
9:23 PM
@Mysticial Haskell's kinda known for shortness, it seems
 
@Jordan output a list recursively. do a quicksort. or any number of other tasks
 
Xeo
@RMartinhoFernandes interesting
 
@CatPlusPlus :D
 
Oh, I was talking about an in-place quicksort. I've done an out-of-place quicksort before.
 
duplicate? You gotta be fucking kidding me
 
user1174868
9:23 PM
@MooingDuck I don't know lists yet
 
qsort (x:xs) = let r, l = partition (<=x) xs in r ++ [x] ++ l
 
@Mysticial you used it where it wasn't needed?
 
Also.
Possibly with (r, l)
 
@Mysticial I've written lots of sorts. quicksort is tricky
 
(x:xs) can't remember what that means?
 
9:24 PM
And we both failed to actually sort anything.
 
@Jordan so learn lists, and you'll suddenly know why recursion is useful.
 
Great job, @RMartinhoFernandes.
And me.
 
@CatPlusPlus Ooops,
 
Dammit.
 
Don't tell anyone.
 
9:24 PM
@TonyTheLion It was a HW exercise.
 
user1174868
@MooingDuck I am working through homework assignments attached to sections of the book I don't want to get ahead of myself
 
Xeo
@TonyTheLion first element of a list.
 
oh yea, x of xs
 
@TonyTheLion Non-empty list pattern. Binds head into x and tail into xs.
 
@CatPlusPlus No one else knows Haskell, so we're in the clear.
 
9:25 PM
@RMartinhoFernandes Lol.
 
@Mysticial technically, I think you're misusing "in-place" (it's common, most people do)
 
Also picking first element as pivot is a crappy way to pick a pivot.
 
No one cares.
 
I know a bit of Haskell
 
Quick sort sucks.
 
9:25 PM
I never finished reading the book I once downloaded
 
@MooingDuck I mean with no auxiliary memory aside from stack variables.
 
@Jordan so don't complain that recursion is useless until after you've learned why it's useful.
 
Merge sort works better for lists.
 
@CatPlusPlus how surprising you say that
:P
 
Nobody uses raw quick sort.
 
9:26 PM
@KonradRudolph Finally! A glider! That thing took forever to produce one.
 
They complicate the implementation until it becomes something else.
 
Xeo
@CatPlusPlus You missed the recursion, right?
 
user1174868
@MooingDuck I never said it was useless, just that the example is because it is so obvious and can't really be further applied to anything
 
@Xeo Yes.
 
@CatPlusPlus Often introsort.
 
user1174868
9:27 PM
I just think that fact can't stand alone as an example, it needs other examples to go with it
 
@Mysticial right. I wrote a quicksort that was in-place, but it was about half the speed as doing it the normal way.
 
@Jordan Recursion is obvious.
 
@Jordan Recursion is a way of thinking. You have to read several examples and develop an intuition.
 
@CatPlusPlus std::unique_ptr<bool[]>(new bool[size]()) :D
 
@MooingDuck Well yeah, if you want pure speed, you do an FFT-style merge-sort. This things are scary.
 
user1174868
9:27 PM
Well I gave up and asked my question, so hopefully someone will tell me instead of me having to think
 
It's out-of-place though.
 
You can always learn mathematical recursion and all of related stuff.
We won't think for you.
 
@Jordan That's the wrong approach.
@ManofOneWay Gosh, you're still on that?
 
hmm, just offered my first ever 500 p bounty
 
Xeo
btw @Mysticial, were you interested in Visual Novels?
 
9:28 PM
If you can't be arsed to think, you can stop programming this instant, because you will never learn anything.
10
 
@RMartinhoFernandes Actually, I just started again
 
Do any modern C or C++ compilers do tail recursion optimization?
 
@JimNorton GCC does.
 
@JimNorton yes
 
Clang/LLVM most likely too.
 
9:28 PM
@Xeo I've never tried any. So I wouldn't know.
 
@CatPlusPlus nice
 
GCC can even transform some non-tail-recursive functions into tail recursion.
 
@JimNorton yeeees! All.
 
@Mysticial can you find a link to an explanation of your FFT style merge sort?
 
Funny because The Mono team is proud to bring you a preview of C# 5.0 a few years before our friends in Building 41 do. was posted 27 Apr 2010. The demo was at the same conference when Anders presented the idea in a 'The Future Of C#' talk — sehe 23 secs ago
 
Xeo
9:29 PM
@Mysticial Oh, okay. Try one, they're fun :)
 
@TonyTheLion Don't need to. I'm the one who invented it.
 
user1174868
@RMartinhoFernandes I am not smart enough to figure this out on my own, it has been 5 days and I want to move on to other material
 
I did a search for FFT sort and got pages on "Final Fantasy Tactics - How do I sort my inventory"
 
It's not worth publishing, but I make a mention of it in my FFT paper.
 
9:30 PM
Inventory tetris the best tetris.
 
@Mysticial oh... so I guess until you write how it works, I won't know how it works
 
The idea is very simple. Merge sort is slow because you need lg(n) passes over memory. (one for each recursive level)
You can do better by splitting into many sub-sizes.
 
right
and then adding them together again?
 
And that's the same basis as the higher-end FFT algorithms.
 
right
 
9:31 PM
@TonyTheLion Same idea, you merge multiple chunks at once.
 
@ManofOneWay I don't understand (I missed the original conversation) what is making it so difficult (and I'm not entirely sure what you're trying to do either).
 
@Mysticial so it's an N-way merge sort instead of 2-way?
 
@MooingDuck Yeah
 
hmmm interesting
 
There's a trade-off through. Merging N things is much harder than merging 2 things.
 
9:32 PM
@Mysticial I was told that was slower than 2-way, to the point it wasn't worth it. Also that's still log(n), just in base N
 
So you trade computation for better memory access.
 
user1174868
@RMartinhoFernandes I really wanted to solve it on my own but I can't, I will never get it no matter how long I work on it if I only do it on my own. I don't know enough about programming to learn it on my own
 
Bullshit.
 
my dumb computer just crashes because it can't allocate the necessary memory. I already looked through examples () of how to use the new(std::nothrow) and how to handle it, but my mac just decides to say I have an error I quit.
 
@Jordan Have you diagrammed out what is happening on the stack in a simple recursive function?
 
9:33 PM
Draw it on a paper.
 
Anyone have the same bullshit behaviour on a mac?
 
@MooingDuck Indeed the amount of computation goes up a bit, but if you're sorting massive arrays that are many times larger than cache. You can probably get away with a 4-way or 8-way split at the top level. (or even more)
 
with g++
 
@Jordan is your question the "why recursion" thing?
 
@RMartinhoFernandes What's making it so difficult is that I suck at C++. What I'm trying to do is to have a consistent way of using bitvectors. 1d bit vector is working nicely with std::vector, but for 2d bitvector it isn't that nice anymore. Sure do a x*y 1d std::vector is fine, but I still have to wrap it into some class. So I'm making BitVector and 2dBitVector classes
 
9:34 PM
@jmlopez It’s normal behaviour on most modern OSes, new always succeeds even if no (physical) memory is available
 
user1174868
@JimNorton Stack?
 
user1174868
@MooingDuck No, I can't ask questions here
 
@jmlopez The reason is that modern memory management subsystems actually don’t allocate memory, they provide it once you actually access the memory, no sooner
 
@ManofOneWay boost::multi_array
 
@ManofOneWay use a vector inside, stop using unique_ptr
 
9:35 PM
Besides I only need a small subset of all the features in std::vector
 
@Jordan Really? You are being taught about recursion without knowledge of what a stack is?
 
The minor drawback of this is that you effectively cannot handle out of memory errors, and you shouldn’t try
 
I don't want to include boost into this either
 
@KonradRudolph he has the opposite problem
 
@ManofOneWay You only need to compute the offset differently. Stop making your life difficult.
 
user1174868
9:35 PM
@JimNorton I am learning from SICP
 
@Jordan I never said to ask a question here
 
You can even implement it generically for N-dimensions if you want.
 
@MooingDuck Are you sure? Doesn’t sound like it
 
But making two implementations for 2 dimensions is silly.
 
@ManofOneWay so? It's still faster, easier, smaller, and better than doing it yoruself
 
9:36 PM
@KonradRudolph, so, how can I make sure that I have the memory?
 
@ManofOneWay vector is not in boost
 
Wrap std::vector and done.
 
@KonradRudolph no wait, I got it
 
@jmlopez On modern operating systems you generally can’t, sorry
 
@jmlopez initialize it to non-zero
 
9:36 PM
Hell, I can do that in 2 minutes.
 
@ManofOneWay Write byte_of(index), bit_offset_of(index), use a std::vector<unsigned char> and be done with it.
 
@MooingDuck And then trap the segfault? Ooooh my, I’d be too afraid to do that
 
@jmlopez or initialize every 4095th byte to a non-zero value.
@KonradRudolph that's the only way I know of, sorry
 
@MooingDuck, but still, how can I catch the error?
 
@jmlopez Konrad pointed out it would be a segfault or something, I'm not sure
 
9:37 PM
@MooingDuck don't you have a race condition if you do that?
 
There, write the rest yourself.
 
@RadekSlupik race? In a single thread? How could it race?
 
so that I can tell myself with a message: "Dumbass, you don't have enough memory"?
 
Okay, that sucks.
 
@Jordan This might help....
http://www.programmerinterview.com/index.php/recursion/explanation-of-recursion/
 
9:38 PM
@MooingDuck multiple processes that run on the same computer, use the same RAM.
 
@CatPlusPlus WTF was that?
 
But you just need operator()(int x, int y), make x + y * width, and delegate to vector::operator[].
@RMartinhoFernandes Nothing.
 
@RadekSlupik so? What's the problem? I have one thread, I initialize stuff, and handle any errors. There's no race condition.
 
What the hell are you discussing people.
Don't use nothrow new, don't trap segfaults for OOM.
 
user1174868
@JimNorton So all recursion has to count down to something that is equal to a fixed number?
 
9:39 PM
@Jordan it has to come to a "stop condition"
 
@CatPlusPlus, why not use nothrow?
 
@MooingDuck if you allocate memory and the OS decides to allocate it when you access it later, another process may already have sucked up all RAM. This may happen just before you set the memory to non-zero.
 
Because you can't use it properly.
Because if you could, you wouldn't be asking for questions related to VMM basics.
So, don't.
It's not meant for you.
Catch bad_alloc.
 
try {
    new foo[100000000000000000000000000];
    std::cout << "can haz memz!\n";
} catch(std::bad_alloc&) {
    std::cout << "no memz for you\n";
}
 
If you can't catch bad_alloc, you lost everything anyway, so don't bother.
Crash and dump core.
 
user1174868
9:41 PM
So then how would fibonacci sequence be recursion? I stops at the user input I guess? But that seems like it requires a counter and it counts up
 
What user input?
 
@Jordan No, all recursion must have a "base case". Once the base case is reached, the recursion stops and the stack is unwound...
 
alright, i'll use a try catch block...
 
I would never care about bad_alloc.
 
Recursion in computer science is a method where the solution to a problem depends on solutions to smaller instances of the same problem. The approach can be applied to many types of problems, and is one of the central ideas of computer science. "The power of recursion evidently lies in the possibility of defining an infinite set of objects by a finite statement. In the same manner, an infinite number of computations can be described by a finite recursive program, even if this program contains no explicit repetitions." Most computer programming languages support recursion by allowing...
 
9:42 PM
I have enough RAM anyway. xD
 
@RadekSlupik The OS will never deallocate memory for you. It might page it, but that's completely different. THe problem you describe doesn't exist.
 
Also you can disable overcommit in Linux kernel, anyway.
 
And don't forget to google "recursion".
 
@RadekSlupik What.
 
user1174868
(define (fib-rec a) (if (= a o)) not really sure
 
9:42 PM
@Mysticial And "recursion visualisation".
 
@Jordan fibb usually counts from user input to zero, but it can also start at zero and count to user input, either way
 
@RadekSlupik WTF are you talking about?
 
user1174868
@MooingDuck But how can it count down? Fibb counts up by adding the two previous inputs
 
fib(a, b, n)
 
Draw the thing.
 
9:44 PM
@Jordan fibb(int i) {return fibb(i-1)+fibb(i-2); } //plus the stop conditions
 
DRAW EEEET!
 
Also, recursive Fibonacci is an example of things you don't do with recursion.
 
You should also google "do a barrel roll"
 
At least not without tail-rec.
And "zerg rush".
 
To understand recursion, you first need to understand recursion.
2
 
9:44 PM
@CatPlusPlus I wrote a super fast fibonacci thing once. Then I realized nobody needs the fibonacci sequence.
 
@MooingDuck Lol.
 
Recursion is better than itself.
 
You must be bored.
 
OMG, finally someone figured it out.
I've been bored to death for the past two hours.
 
9:47 PM
Why should I use std::vector<unsigned char> instead of std::vector<bool>? What is it that doesn't work with the boolone?
 
Play DF.
 
@ManofOneWay If you want a bitmap, vector<bool> is fine. You just need to be aware that it's a bitmap, and not a vector of bools.
And that's why we generally don't like it.
It's misleading.
Violates principle of least surprise, or whatever the name of that was.
And I'm done discussing bitmaps for this month. :.
 
user1174868
I can't wrap my head around how recursion knows when to stop with fib
 
See above. When n is 1 or 0.
 
user1174868
9:51 PM
That seems wrong though, because if you want the 10th term it will give you 9 + 8 and such, those aren't fibb numbers
 
@Jordan fibb(10) = fibb(9) + fibb(8), not 9+8
 
user1174868
?
 
The drawing is correct. Look closer.
 
> I like to draw diagrams to explain stuff.
 
@EtiennedeMartel Yeah, but in this context. Damn.
 
9:53 PM
@Jordan so you complain that fibb is a useless example for recursion, and it turns out it's too complicated for you?
 
user1174868
@MooingDuck Factorial
 
@Jordan oh. right
 
@CatPlusPlus You should drink beer.
 
user1174868
because factorials input is exactly all that is needed
 
@Jordan they're remarkably similar, if you get factorial, you make almost no changes to get fibb.
 
user1174868
9:54 PM
with anything else you need other stuff
 
The irony is Fibonacci actually is an useless example for recursion. :v
 
How's fib any different?
 
Well, on purpose, but still.
 
user1174868
Because there is an abritrary input that doesn't give a value to the function
 
What.
 
9:54 PM
Wut?
 
@Jordan wat
 
whut?
 
user1174868
f(8) really is not related to the number 8 is any way, except that it is the 8th erm in the fibb sequence
 
And 8! is related to 8 how?
 
user1174868
(* 8 (fact (- a 1))
 
9:55 PM
how? gr8tly!
 
user1174868
or whatever
 
@Jordan oh right, you do scheme
 
user1174868
that can't be done with fibb because the value doesn't come from 8 it comes from counting up to 8
 
I have no idea what you're trying to say.
 
user1174868
where in factorial that value starts with 8 and counts down to a base case
 
9:56 PM
hello all
headdesk
I don't understand why this is upvoted so much, using standard language features (in this case, a simple struct) is much cleaner and quicker than invoking boost. — KomodoDave 3 mins ago
 
@JohannesSchaublitb hello :)
 
(+ fibb (- a 1) fibb ( - a 2) )
 
Other than "factorial is not defined the same as fib".
 
user1174868
with fibb with an input of 8 you have to count up to 8 to figure out the value of the 8th terms
 
Which is, well, kinda obvious.
 
user1174868
9:57 PM
The way the functions work are very different to me
 
of course, he downvoted me
 
One operates on three terms with +, one operates on two terms with *.
That's the only difference.
 
user1174868
One is simply calculated at 8*7*6*5*4*3*2*1*1, the other is calculated at 8 (0+1+2+3+5+8+13+21) or whatever
 
user1174868
I am not sure how to handle fib counting down to a base case
 
user1174868
9:58 PM
I am not sure hwat the base case could be
 
@JohannesSchaublitb apparently he is not a big fan of Boost.
 
8 mins ago, by R. Martinho Fernandes
See above. When n is 1 or 0.
 
user1174868
But how do you count down to taht
 
9:58 PM
@Jordan the base case is if a<1 return 1
 
By subtracting 1 from counter until it reaches 0.
 
@Jordan how do you do if in scheme
 
And then returning 0.
 
@jweyrich he still has it on
 
user1174868
(if predicate condition) I think
 

« first day (633 days earlier)      last day (4315 days later) »