last day (894 days later) » 

user142019
21:00
@FredOverflow I once wrote an implementation of pattern matching similar to std::tie. Give me a second to find it back.
@Zoidberg I don't understand this, what is the semantics of {a, b, c} = myObject? Assign the fields to three local variables?
user142019
It does this:
user142019
a = myObject.a;
b = myObject.b;
c = myObject.c;
Did you have to chose the names a, b and c for both purposes? :)
user142019
The order doesn't matter; you could've done {a, c, b} = myObject and it would've been the same.
21:01
@Zoidberg What is that?
@Zoidberg oh
user142019
@MooingDuck It creates an object (think, hashtable) and assigns the values to variables.
@Zoidberg lolwut
@Zoidberg that makes no sense
So the names have to be the same?
@Zoidberg Are we done with your Java quiz already? :(
user142019
@FredOverflow coffeescript.org/#destructuring /cc @MooingDuck
user142019
21:02
user142019
@MooingDuck why not? It takes the same names. It basically unpacks an object into variables.
@Zoidberg I'm more interested in usage examples than implementation.
user142019
futurists =
  sculptor: "Umberto Boccioni"
  painter:  "Vladimir Burliuk"
  poet:
    name:   "F.T. Marinetti"
    address: [
      "Via Roma 42R"
      "Bellagio, Italy 22021"
    ]

{poet: {name, address: [street, city]}} = futurists
in Lua, if you have a,b,c,d it makes a magic array thing, and all functions take that array thing. But it also allows you to return such a list: return 3, 5, "apple";, and the reciever has myvar1, myvar2, mystring = function(); to get them all. That's nice.
user142019
@MooingDuck keys are unordered.
user142019
21:04
@FredOverflow I don't have a usage example of it anymore. Let me write one. :P
@Zoidberg requires the names to be the same, I don't see the use for it
user142019
int a, b;
double c;
match_tie(a, b, predicate<int, std::equal_to<int>>{42}, c) = std::make_tuple(1, 2, 42, 3.14);
user142019
@FredOverflow ^ something like that.
user142019
If you change 42 to something else in either the predicate or the make_tuple, it throws bad_match.
user142019
Though the predicate syntax is extremely verbose. xD
21:08
@Zoidberg match_tie?
user142019
6 mins ago, by Zoidberg
@FredOverflow https://gist.github.com/4676945
user142019
It's like std::tie(a, b, c) = my_tuple; but does pattern matching before assignment.
user142019
It's very crappy and unreadable. Don't use it.
template<class T>
predicate<T, std::equal_to<T>> force_equal(T val)
{return predicate<T, std::equal_to<T>>(42);}
match_tie(a, b, force_equal(42), c) = ...
wait, wtf. you inherit from int?
user142019
@MooingDuck No?
user142019
21:11
The only inheritance in that code is from std::runtime_error.
Do we have a policy against GIFs here? :)
@Zoidberg no wait, nevermind
user142019
@FredOverflow No.
user142019
Also, Lounge is unfair.
user142019
21:12
Animated SVGs get binned.
user142019
Pin it!
Is the anti-gif policy only restricted to animated sprites?
@FredOverflow NSFW?
This is not the Lounge, so what.
@FredOverflow because I'm at work, and it's polite
user142019
21:13
user142019
Look at that for ten hours straight.
@Zoidberg The scary thing is that I am feeling a strong urge to do that.
41 secs ago, by Zoidberg
user image
Oh, interesting, it's still animated.
@Zoidberg yeah, that seems really overly complicated.
@Zoidberg or maybe there's a use-case it handles that I haven't thought of
user142019
If you want pattern matching, use Haskell or Erlang.
user142019
21:15
ALSO C++ CASE Y U RESTRICTIVE.
@Zoidberg i18n is hard
user142019
How is that related to case?
user142019
I mean switch case.
user142019
There could be operator case(T a, T b) which returns a bool and defaults to operator==.
user142019
It would allow for very neat things such as this:
user142019
21:16
switch (true) {
    case (a > b): foo(); break;
    case (a == b): bar(); break;
    case (a < b): baz(); break;
}
user142019
:D
@Zoidberg I assumed uppercase
user142019
There is no reason whatsoever to restrict switch-case like C++ does that right now.
@Zoidberg defeats the point of switch though, what you wrote is the same as a bunch of if statements.
user142019
Except it's a thousand million times more readable.
user142019
21:18
@MooingDuck The jump optimization can still be applied if all cases are constant expressions.
@Zoidberg because it can optimize to jump lookups. Your way it must check all of the conditions one by one, can't be optimized to a jump
@Zoidberg that "optimization" is the only purpose of a switch
user142019
And readability.
user142019
switch is very elegant IMO.
@Zoidberg no, that wasn't the purpose of a switch.
user142019
It can become on of the purposes of a switch.
21:20
@Zoidberg I disagree
user142019
I don't.
@Zoidberg well obviously :D
user142019
lol everyone is joining.
One word: verbose
user142019
Java is boring and uninteresting.
user142019
21:21
That's the main issue.
user142019
It has no interesting features whatsoever.
When I was first told about what Java & what it was supposed to do, I was given the impression that the only people who use it are banks. lol
user142019
My bank uses Haskell for something.
user142019
Quite neat.
user142019
Because Haskell is teh awesomezt.
21:24
You mean they use software. Which happens to have been written in Haskell.
I'm pretty sure my bank is run by robots.
user142019
@AndreiTita ;_;
user142019
They indirectly use the Haskell runtime, ok?
Every Tuesday around 1pm, my card gets tagged for fraud.
user142019
lol
user142019
21:25
Buy a new card.
This is my third one :/
1. Buy new bank
2. ???
3. Profit
I'm switching today.
Stop using it for fraud then.
user142019
lol
21:26
Yeah, I agree @AndreiTita. But the Middle East are my only option for gas right now :D
It's tough to be a gangsta :(
Until another country steps in, I'm forced to buy gas from the fraudulent middle east.
What languages do you all love?
@jsksma2 C++, Lua, Haskell
I'm likely just about to start using C++ for a new job.
I'm iOS, and it's a game dev job.
@jsksma2 Who are you, and how did you find us?
21:34
I am 4% of the programming world according to GitHub :)
Correction, 3% lol
@Zoidberg I blame it on your username. Yes, that must be it :-).
@jsksma2 C++, Lua, hmm... I like MATLAB too.
> The term ObjectOrientedLanguage is usually defined to mean a ProgrammingLanguage that supports ObjectOrientedProgramming. However, there seems to be no consensus on what "object-oriented programming" and "supports" mean.
matlab? that's like PHP with one or two redeeming features?
21:36
@FredOverflow haha
@AndreiTita I write node as well. I used to be a front-end web developer, but I picked up iOS, and I really like it.
I've used C++ overwhelmingly, really. I'm not very well-rounded.
in Java, yesterday, by Doorknob
Getters and setters are highly overused
I'm more so the opposite. I've been jumping around languages for the last 5 years! I'm still young though, so I have time :) I do really enjoy ObjC though. I'm sure I'll enjoy C++ even more.
21:43
I love templates, but the rest of C++... is often a mess.
Still, fastest language there is pretty much.
Java sucks? Tell me which language doesn't suck.
who said there were languages that didn't suck?
@EamonNerbonne I haven't really looked into how OpenGL and C++ works for the iOS yet. But I will take note of that when I'm starting out :)
@jsksma2 iOS doesn't support OpenGL (...only OpenGL ES). :-)
This should be an interesting read.
21:48
Don't take it too seriously :-). It's just that C++ is about as big as most other major languages put together, and it's old, and there are 100 different ways of doing anything and many basic operations are not or poorly standardized.
@JerryCoffin yes, sorry.
So that's not necessarily killing - you just need to be much more structured than in many other languages.
@EamonNerbonne What operation isn't standardized?
I have never worked with any game dev besides messing around with ro.me a bit. I can imagine that I'll have no choice but to take it light-heartedly lol.
in Lounge<C++>, Jul 13 '12 at 15:57, by FredOverflow
@RMartinhoFernandes BREAKING NEWS: Language wars finally over. Preliminary result: every major programming language sucks.
@EamonNerbonne If you count the standard libraries, C# is waaayyyyy bigger than C++.
21:50
@FredOverflow It could be worse, you could be a lawyer
@jsksma2 What could be worse?
@FredOverflow You don't seem to love programming that much. Especially because you have a mere 56.4k reputation on here :P
@FredOverflow It looks to me like it was written by a Java advocate carefully excluding many of the worst problems.
@JerryCoffin There's lots of reinventing of wheels.
And the styles are vastly different.
You take a java programmer and move him to a different java codebase; there's a good chance he'll understand much of what he sees
not so with C++
(well, there's a chance, of course - but it's lower)
Do you reuse via inheritance?
functionally?
via CRTP?
generic programming?
Even basic things like modules aren't standardized.
So lots of C++ interop happens (ironically) via C interop layer
@EamonNerbonne Well, it is true that in Java almost everything is irretrievably bad, while in C++ you occasionally run across something that's at least half decent.
21:55
that's because different compilers and different versions of the same compiler can't call each others libraries - generally not even with glue
yeah :-)
I'm just saying that it's a pretty vast forest in C++ land
and things you take for granted everywhere else just aren't there
@EamonNerbonne Do you know what the problem with "multiple inheritance" is? Hint: it is not the "multiple" part.
@EamonNerbonne Yes, this is very sad :(
Yeah, inheritance as a paradigm is... less than ideal
but it has it's uses occasionally.
It's great for mix-ins.
which are terrible without multiple inheritance :-)
@EamonNerbonne Is that interface inheritance as in Java?
21:58
No, I mean C++-style inheritance.
@EamonNerbonne The reverse is also true though. How many other languages' standard libraries include anything roughly comparable to C++'s algorithms or iterators? D is sort of working on it, but that's about the only one you can even compare.
so you can actually get behavior too.
don't get me started on iterators.
Really terrible design
terribly impractical - I find myself constantly jumping through hoops to avoid iterators in C++.
@EamonNerbonne lol @ "Virtual inheritance mountains" and "Diamond mine" :)
@EamonNerbonne It would be nice to combine two iterators into a "range". I think they're working on that.
22:00
@EamonNerbonne Like democracy -- the worst there is...except for everything else anybody's tried (well, with enough work ranges might end up as a replacement, but nobody really knows how to do them right yet).
yeah, they are... that would be much much better.
well, the rest of the world does
that's what python's generators and C#'s enumerators are, really.
@JerryCoffin You would think that combining two iterators into a range couldn't be that hard :)
@EamonNerbonne So why does everything that uses ranges suck so badly?
what are you referring to?
more specifically :-)
@FredOverflow You might, but you'd be wrong.
22:03
well, boost has ranges and they sorta work
so does D
certainly both work better today than iterators
just in C++ they suffer from being in the vicinity of iterators
Are D ranges built upon iterators, or are they "fundamental"?
Don't know
boosts are a little bit of both
and complexer for it.
> Amazing map. I'm rather missing the vast armies of RAII marching in to bring the decisive strike against the forces that besiege the castle of dynamic memory ;-)
@EamonNerbonne Look on SO and look at the number of questions that are "how do I do this more Pythonically?" Most answers will typically involve either list comprehension or generators or both, but nearly always be something so thoroughly counterintuitive that 1) other Pythonistas initially claim it won't even work, and 2) is so thoroughly twisted, nobody really understands it (in some cases even including Guido himself).
22:06
that's a feature the rest of the world misses sorely :-)
"Concepts shipwreck" lol
@FredOverflow They're at least intended to be fundamental.
@JerryCoffin see, that's a good sign :-D There's a reason nobody tries that in C++-land. It would make your head go boom.
I mean to say that list-comprehension-like functionality is implementable in C++ (even pre-C++11), it's just really really really confusing.
@EamonNerbonne If you think that's good, you've clearly lost any relationship with reality.
:-)
I do my best.
The point is: you can try to get it right in python. You might succeed despite lack of static type system. It's harder in C++, even though this is typically something the type system makes much easier (witness haskell, or F#, or LINQ)
all of which are so much simpler than C++ iterators they end up raising the level of abstraction quite a bit.
22:11
@EamonNerbonne They would if they had a clue. Look at the number of times people use "finally" and/or try/except clauses in things like C# and Java, and figure that virtually every one of those could be written cleanly instead, if only they'd used C++ and RAII.
yeah, RAII is great.
Without iterators, how would the signature of std::min_element look like? What would it take, what would it return?
@JerryCoffin C# has using, and Java has ARM ("try with resources") now.
urgh
using is a really poor replacement for RAII
doesn't really work.
everybody forgets it
It works locally :)
API's use it inconsistently
some even recommend not disposing (Task<> springs to mind)
22:13
@FredOverflow It's about like the old programs that could show longer names in place of DOS 8.3 file names. Still a complete mess, but just good enough to keep anybody from bothering to really fix the problem for a long time.
Why are we discussing C++ outside of the Lounge? Oh wait :)
so uhm std::min_element
In other words: a solution that's actually worse than none at all, because is conserves the problem instead of fixing it.
how's that iterator specific?
22:14
@EamonNerbonne It returns an iterator :)
sure, so it could return a range
A range with one element?
which is the same but better because it has a safe end
no, that's the point: there's a distinction here
either
you want a single least element; in which case you want Maybe<element>
or you want the position of the least element as part of a range
that can be useful as part of other algs, though likely min_element itself not so much - there are others where it makes more sense
In the list [3, 7, 4, 1, 2], what range would std::min_element return?
so then what you're really returning is the range [min-element, last)
So: which API style do you prefer?
22:17
Why on earth would you do that?
binary search
(no, not min_element itself)
@FredOverflow Because all the elements after the minimum are clearly minimum too. What a silly question!
but the API looks like it was chosen for consistency with others like it.
right, the name of the iterator-based function is misleading
@ScottW What makes you say that?
So in practice, min_element should be: Maybe min_element (ForwardRange range);
(and you'd want a different function to split by minimal element)
22:21
@EamonNerbonne ...and the advantage of this would be...what?
you mean the splitting?
@EamonNerbonne Aren't you missing a type argument to Maybe?
sure, it's pseudocode
and I don't know of a Maybe like this anyhow.
(in C++)
boost::optional
22:23
But I don't want an optional element, I want an optional iterator, but if there are no iterators, what do we do?
in anycase, I'll just call Maybe a template parameter, then it's valid :-)
@EamonNerbonne I mean returning a Maybe<something> instead of an iterator to indicate one specific position.
Why do you want an optional iterator?
I think that's part of the problem with C++ ranges as is: they are not exactly the same as as iterators. You wouldn't translate the entire API exactly function by function.
but in the [3, 7, 4, 1, 2] example, I'
d want to get 1 returned, not a range containing 1
In any case, the real strength is with things like map and filter
assert(!v.empty());
auto it = std::min_element(v.begin(), v.end());
*it = 42;
which are really nasty to express with iterators.
22:27
^ How do I do this without iterators.
well that code implicitely assumes such an element exists
and it assumes you want an API targetted towards mutation
in which case you want references
but there's no reason that reference couldn't itself be optional, right?
@EamonNerbonne That turns out to be useless more often than not though. Just for example, let's assume you want to code up a selection sort. If min_element returns an iterator, it's pretty easy to do by swapping the first unsorted element with the min_element. If you return the value instead, you can't do anything with it.
@EamonNerbonne What do you mean? There are no null references in C++.
no; an optional reference
And I don't know if boost::optional<X&> works.
22:28
Well: it should :-)
If it works, it's probably implemented as a pointer.
the point is that you're not going to replace iterators with ranges on a 1-1 basis without any other changes.
it just can't happen.
In any case, for that I think I'd want a different function that splits the range into two:
How would you implement min_element if all you have is a range?
@EamonNerbonne Probably not -- that's part of why coming up with ranges that really work is such a problem. Most languages that use ranges just ignore it by failing to provide the kinds of things that are hard to express as ranges.
random google for an F# list split: stackoverflow.com/questions/4866640/…
this is very similar to min_element, though more complex
so cut_by_min(range) would return a tuple of ranges (before_min, starting_at_min)
without losing generality of the current min_element.
and with the advantage of greater type-safety
(since you cannot mix up the iterators)
22:36
waaazaaaaap
also, booobies
22:47
@JerryCoffin But why not mix-n-match?
that might be best for something like min_element anyhow
input:range; output:iterator.
@EamonNerbonne So what does our hypothetical insertion sort look like using this? With iterators and min_element, it's trivial and easily shown correct. This sounds comparatively clumsy to me. At first glance, I'd end up further splitting the list with the minimum element, adding that one-element range to my list of sorted items, then splicing the list of unsorted elements back together (or something on that order).
and then standard tooling to interpret an iterator within a range (i.e. to be able to split the range into before and after parts)
I think that's a bad example
Seriously, insertion sort?
how about consecutive filters?
:-)
or bind?
@EamonNerbonne Just picking a really simple example. There are obvious many others.
yeah, but I think that the iterators strength lies with really low level manipulation but these are things that you just don't need to do that often.
whereas mapping and filtering is something I do all the time, all over the place
I mean, C++ sorta acknowledges that; right:
after all for and if are built-in for a reason.
Well, filtering is rather awkward in C++:
std::copy_if(v.begin(), v.end(), some_predicate, std::back_inserter(result));
22:51
Sure, sometimes you need explicit gotos or whiles with complex breaks - but I don't think the standard library is better for it for making that the most common representation.
exactly.
And copy_if wasn't even part of C++03 :)
oh, and that declaration hides the real atrocity: what's back_inserting doing?
Because it's not doing what it should be doing: making a new iterator.
@FredOverflow A filter_iterator is not only possible but has been part of Boost for years. boost.org/doc/libs/1_52_0/libs/iterator/doc/…
yeah, it's possible, and also really messy and unhandy
@EamonNerbonne It's pushing back into a vector.
22:53
right: not composable.
not lazy.
not efficient
@JerryCoffin I assume that one is lazy?
almost certainly.
@EamonNerbonne Laziness is not C++'s strong suit.
yeah, but that's not really intrinsic to C++'s nature
a range-based filter is easy to get lazy, even in C++
So, what was saying again...
right: that's why java sucks!
@FredOverflow I believe so.
22:56
The frustrating irony is that whereas C# and python implement the laziness with a hefty dose of abstraction penalty, due to the inlinable nature of templates, C++'s filter would probably work better in the first place.
Anyhow; totally off track :-)
@EamonNerbonne In my opinion, laziness without Garbage Collection is rather dangerous. Please don't kill me now :)
you're probably right
I just want it all!
Oh, and can I have Go's static duck typing while I'm at it?

  last day (894 days later) »