Open Side Menu Go to the Top

05-17-2015 , 04:31 PM
I still can't explain monads to someone succinctly which means I haven't understood them -> can't quite understand Haskell

Edit: I think it's just chaining of sorts (of stuff wrapped as anonymous functions) and a monad is the type that allows for the bind. You can do some stuff between the chaining which is where the fun happens.

Last edited by clowntable; 05-17-2015 at 04:42 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
05-17-2015 , 05:05 PM
Quote:
Originally Posted by daveT
Not sure if anyone else experiences this, but using a bunch of hot-keys and drop down menus to tab-complete code I never read or wrote causes considerable disconnect from what I'm writing.
I think you may want to eventually go back to trying it because some people dismiss it for not feeling natural when they first try it. It is faster but not necessary and something that is never mentioned at my university.

It would be funny if professors were teaching intro to java and were like just press shortcuts and bam. People would be so lost lol.

I think it is comparable to using a terminal for the first time and navigating compared to using finder.

I'm not all shortcuts, I'll create a class and just manually write the code for methods I want in that class most of the time.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 05:13 PM
https://en.wikipedia.org/wiki/Monad_...ming%29#Axioms

In functional programming, a monad is a structure that represents computations defined as sequences of steps: a type with a monad structure defines what it means to chain operations, or nest functions of that type together. This allows the programmer to build pipelines that process data in steps, in which each action is decorated with additional processing rules provided by the monad. As such, monads have been described as "programmable semicolons"...
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 05:22 PM
Yah I would think you are missing out in functional programming, since that is where the quick method create really shines.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 05:29 PM
Quote:
Originally Posted by iosys
I think you may want to eventually go back to trying it because some people dismiss it for not feeling natural when they first try it. It is faster but not necessary and something that is never mentioned at my university.

It would be funny if professors were teaching intro to java and were like just press shortcuts and bam. People would be so lost lol.

I think it is comparable to using a terminal for the first time and navigating compared to using finder.

I'm not all shortcuts, I'll create a class and just manually write the code for methods I want in that class most of the time.
When I was working at the C# place, it wasn't *that* bad and I got used to it. I still felt a little tripped up on certain functions.

When I first tried to learn programming, Java was a language I was dipping into. I wrote everything out: public static void whatever (String[]) etc. I actually felt like syntax knowledge was the cornerstone of programming, never mind the fact that I forgot what I wrote by the time I finished the function. It also didn't help much that I had no clue what all those words meant at the time. I think this is where a lot of the "Java for first language sux" comes from.

Declaring the return type and showing if a function *does* return anything at the beginning doesn't strike me as a bad idea though.

Verbosity isn't so black and white that you can visually make out the meaning. Lisp is very dense and compact. If you really think about it, saying you can write 50 LOC of Java in 3 LOC of Clojure just shifts the goal posts of verbosity. Either way, you have to spend time grokking that **** and certainly one is much more difficult to do than the other.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 05:47 PM
Quote:
Originally Posted by clowntable
I still can't explain monads to someone succinctly which means I haven't understood them -> can't quite understand Haskell
Learning some haskell will help you understand monads moreso than the other way around imo. I slowly picked away at the book 'Learn you a haskell' over a month or so and it's easy when built up to from applicative functors and monoids.

It's all just basic programming concepts with big words.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 06:18 PM
Quote:
Originally Posted by daveT
https://en.wikipedia.org/wiki/Monad_...ming%29#Axioms

In functional programming, a monad is a structure that represents computations defined as sequences of steps: a type with a monad structure defines what it means to chain operations, or nest functions of that type together. This allows the programmer to build pipelines that process data in steps, in which each action is decorated with additional processing rules provided by the monad. As such, monads have been described as "programmable semicolons"...
was this supposed to be an example of clear, succinct explanation?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 07:15 PM
Having to put void is a weird complaint about static languages. The 0.1 seconds it takes to put void is repaid in spades when the compiler catches that i forgot the return statement in a non void method, rather than me debugging to find out why all my tests fail.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 08:24 PM
Quote:
Originally Posted by gaming_mouse
+1. i had an original kindle earlier, and was skeptical about the backlighting on the paperwhite, but you can turn it down to nearly nothing, so that in normal light it looks just like it predecessors, and the backlighting is nice to have when reading in the dark.
yeah but its a pain in the ass to get PDFs to work good
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 09:28 PM
Quote:
Originally Posted by greg nice
yeah but its a pain in the ass to get PDFs to work good
true, but pdfs suck on all kindle models except the dx.

it would be nice if someone could invent a pdf to mobi/epub converter that actually worked well, but i think that's a hard problem to solve in the general case.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 09:52 PM
why bother? why not do another DX style e-reader that doesn't cost over $1000?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 11:32 PM
Thinking about the coming from dynamic to static languages, I think one thing dynamic fans are missing is the IDE support that can be provided in static languages.

ASP.NET Webforms has the methods Response.Redirect() and Server.Transfer() for redirecting users around the app. These are both void methods that actually do the work of transferring the users. ASP.NET MVC has Controller.RedirectToAction(), but it does nothing in itself - it returns an ActionResult object that has to be returned as the result of an action method. First time I tried to use RedirectToAction(), I just called it. Nothing happened, because it generated a Result object that I was ignoring. I was confused for about 30 seconds before mousing over the method and noting that it had a return value. Now that I use the IDE enhancer ReSharper, if I do that again it gets underlined with a warning that I am discarding the return value. This sort of thing doesn't seem possible in dynamic languages.

These sort of niceties have definitely gotten less important with the rise of unit testing and the ability to look up problems in 10 seconds on StackOverflow. But still, if you look at static languages in Notepad and go "omg y u make me type void?!" you're only seeing half the story.

(Note, while the only dynamically-typed language I've written a lot in is JavaScript, I don't have anything against them in theory. I'm not sure I'd want to use one to write a really big application, though).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 11:41 PM
Quote:
Originally Posted by daveT
why bother? why not do another DX style e-reader that doesn't cost over $1000?
that would be nice, but honestly even if it was free most times i'd prefer to read a perfectly converted mobi just because the normal sized kindle is better to hold.

ofc, some texts really can't be converted. in that case, i'll wait for the DX version that feels like and is as light as a laminated piece of paper... should be what... 10, 20 years?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 11:48 PM
Quote:
Originally Posted by ChrisV
Thinking about the coming from dynamic to static languages, I think one thing dynamic fans are missing is the IDE support that can be provided in static languages.
i've recently been doing javascript editing in webstorm, and it seems to have a Java-like comprehension of the code. I believe it actually runs it somehow to make inferences and stuff. It has intelligent code completion, nice structure view, including private and public var created using closures, jump to definition, etc. Feels like a Java or C# IDE. It's much nicer than I was able to get my raw vim setup, even with ctags and stuff. And with the IdeaVIM plugin and dark theme, jump to symbol or file, I don't miss much.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-17-2015 , 11:49 PM
how do you guys feel about stuff like "auto" in static typed languages like C++? some are really for it, some are way against it. I don't see the need except laziness but others see more readability.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-18-2015 , 04:09 AM
Quote:
Originally Posted by jmakin
how do you guys feel about stuff like "auto" in static typed languages like C++? some are really for it, some are way against it. I don't see the need except laziness but others see more readability.
Personally I never use auto (just don't).
I've read that people dislike it, they prefer not to read it, so there is that reason to not use it.

I don't really know why people dislike it or like it.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-18-2015 , 04:25 AM
Thats like var in C# right? I like it but only use it when it enhances readability. If the type name is like 100 chars long because its some nested generic, then yeah. If the type is int, then lol no. ReSharper has always using var as a style hint. I forget the rationale but I remember that I disagreed with it.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-18-2015 , 07:16 AM
Quote:
Originally Posted by gaming_mouse
i've recently been doing javascript editing in webstorm, and it seems to have a Java-like comprehension of the code. I believe it actually runs it somehow to make inferences and stuff. It has intelligent code completion, nice structure view, including private and public var created using closures, jump to definition, etc. Feels like a Java or C# IDE. It's much nicer than I was able to get my raw vim setup, even with ctags and stuff. And with the IdeaVIM plugin and dark theme, jump to symbol or file, I don't miss much.
PyCharm is pretty good too. You can even get type support in the code complete/popup helpers but it requires using type hinting in docstrings.

Although type hinting in docstrings does require a lot of will power to keep up, it's a lot of extra typing.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-18-2015 , 10:34 AM
Quote:
Originally Posted by jmakin
how do you guys feel about stuff like "auto" in static typed languages like C++? some are really for it, some are way against it. I don't see the need except laziness but others see more readability.
Quote:
Originally Posted by iosys
Personally I never use auto (just don't).
I've read that people dislike it, they prefer not to read it, so there is that reason to not use it.

I don't really know why people dislike it or like it.
There are some places where it really is worth it imo, usually dealing with today's template libraries that tend to create verbose types:

Code:
SomeType<OtherType>::SomeOtherType pObject = new SomeType<OtherType>::SomeOtherType();

auto pObject = new SomeType<OtherType>::SomeOtherType();
Code:
for(typename std::vector<T>::iterator it = x.begin(); it != x.end(); i++)

for(auto it = x.begin(); it != x.end(); i++)
Code:
std::pair< std::unordered_multimap<std::string,std::string>::iterator,
       std::unordered_multimap<std::string,std::string>::iterator> range;
range = words.equal_range(max_string);

auto range = words.equal_range(max_string);
Code:
for (const SomeType<OtherType>::SomeOtherType& thing : thingCollection)

for (const auto& thing : thingCollection)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-18-2015 , 04:41 PM
Yah those examples sure make it look cleaner.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-18-2015 , 06:30 PM
Yeah in c# I think factors that make it a good spot to use var are:

1) The type name is unreadable gibberish
2) You're about to be told what the type is again (eg newing up an instance)
3) The type doesnt matter for some reason (eg it's about to be serialized to JSON)

In just everyday statements like "var customers = dataSource.GetCustomers" I'm against the use of var. Finding out what type that is is at best an interruption to my train of thought (having to mouseover var and wait for the tooltip) and at worse a horrible inconvenience (if I'm reading it somewhere without intellisense). And I dont see any benefit to using it.

One of the supposed benefits the ReSharper guys listed was encouraging better variable names e.g. "customersList". Problem is I think thats a terrible idea. I'm big in favour of semantic variable names and routinely have names like "customersWithActiveOrders". Am I supposed to make this "customersWithActiveOrdersList"? "listOfCustomersWithActiveOrders"? Why am I making my variable name less readable when theres a perfectly good place available to tell you exactly what the type is?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-18-2015 , 06:34 PM
Note also that in C# there are places where there is no option but to use var (anonymous types). Not sure if thats the case in C++
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-18-2015 , 06:45 PM
If it's too long, the alternative is to use typedef to shorten the name.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-18-2015 , 09:51 PM
Quote:
Originally Posted by jmakin
how do you guys feel about stuff like "auto" in static typed languages like C++? some are really for it, some are way against it. I don't see the need except laziness but others see more readability.
If interested, here is a really good article about auto and ways to use it to avoid programming problems. It is written by C++ guru, Herb Sutter. To me it was very interesting.

Herb Sutter Article on When to Use the auto keyword

I think it is fair to say that one of the primary reasons is that it is fairly easy to have implicit type conversions that are hard coded cause problems. It is better practice to let the compiler deduce types on the left hand side of the equal sign whenever possible.

Related to the points Benholio made:
Quote:
(a) will not compile
// (a)
void traverser( const vector<int>& v ) {
for( vector<int>::iterator i = begin(v); i != end(v); i += 2 )
// ...
}
With (a), the most important pitfall is that the code doesn’t compile. Because v is const, you need a const_iterator. The old-school way to fix this is to write const_iterator:

vector<int>::const_iterator i = begin(v) // ok + requires thinking
However, that requires thinking to remember, “ah, v is a reference to const, I better remember to write const_ in front of its iterator type… and take it off again if I ever change v to be a reference to non-const… and also change the “vector” part of i‘s type if v is some other container type…”

Not that thinking is a bad thing, mind you, but this is really just a tax on your time when the simplest and clearest thing to write is auto:

auto i = begin(v) // ok, best
Using auto is not only correct and clear and simpler, but it stays correct if we change the type of the parameter to be non-const or pass some other type of container, such as if we make traverser into a template in the future.

Guideline: Prefer to declare local variables using auto x = expr; when you don’t need to explicitly commit to a type. It is simpler, guarantees that you will use the correct type, and guarantees that the type stays correct under maintenance.

Although our focus is on the variable declaration, there’s another independent bug in the code: The += 2 increment can zoom you off the end of the container. When writing a strided loop, check your iterator increment against end on each increment (best to write it once as a checked_next(i,end) helper that does it for you), or use an indexed loop something like for( auto i = 0L; i < v.size(); i += 2 ) which is more natural to write correctly.

Last edited by adios; 05-18-2015 at 10:01 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-19-2015 , 11:38 AM
First final done. Needed a 50 to get an A, felt like I was getting around a 30, ended up with a 75.

One left and then the semester is done, aside from one assignment. Then no more c++, wooooo!!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m