Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 361 362 [363] 364 365 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886814 times)

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5430 on: February 13, 2014, 08:15:19 pm »

Python is so awesomely easy x3
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5431 on: February 13, 2014, 08:51:33 pm »

Python is so awesomely easy x3

At least until you try setting up some form of web framework hosted on an up-to-date Arch box.

No, I'm not bitter.
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5432 on: February 13, 2014, 11:35:20 pm »

Duck typing simplifies a lot of things, yes.
C++ has duck typing too with templates :P

The newest standard supports it in general doesn't it?  Auto types or something?  I admit to not keeping up with the changes in C++ lately.  Last time I looked I didn't understand the point of some of the new features and hated the syntax of most of the rest.  Ah well, probably for the best that I don't code in it too much these days.  :)
Logged
Through pain, I find wisdom.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5433 on: February 14, 2014, 12:04:37 am »

Duck typing simplifies a lot of things, yes.
C++ has duck typing too with templates :P

I really hope this was a joke.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5434 on: February 14, 2014, 03:38:57 am »

The newest standard supports it in general doesn't it?  Auto types or something?
Nah, auto is compile-time and just make it easier because of not having to make long typedefs, or having to type weird long iterator names.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5435 on: February 14, 2014, 05:07:20 am »

Most of the new C++11/14 language features are either things that have been tried and tested and proved pretty damn useful in other languages (type deduction, yay! lambdas, yay!) or things to do with metaprogramming to simplify that whole mess (variadic templates, yay! constexpr, yay!). I now consider C++ a more syntaxically modern language than Java, which is only just getting Lambdas next month and still no type deduction because reasons -_-

Personally I am not a big fan of how most languages handle duck-typing. It can make small things simpler, but it makes big things more complicated due to a lack of constraints. Makes it harder to follow what a function is doing, and forces me to jump around the source code or god forbid, the documentation, more often. I tend to think if I have to go into the documentation, someone has failed somewhere. We all fail at times, and a trip to the documentation is inevitable especially at first, but a measure of quality of a language/tool/library is how much it limits the amount of time I spend out of the IDE :)

I kinda prefer how Scala or Typescript handle it, where you can define the interface something must implement, but it doesn't necessarily need to actually inherit from that interface. It just needs to have implemented those functions. This is duck-typing I could get behind because the IDE can still easily deduce what I could put in there, present me with that information, and as a result save me a few trips. It's why it's a pitty concepts haven't made it into the C++ standard yet.
« Last Edit: February 14, 2014, 05:19:39 am by MorleyDev »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5436 on: February 14, 2014, 07:26:57 am »

It's why it's a pitty concepts haven't made it into the C++ standard yet.
OTOH, C++ has multi-inheritance so you can just as well use abstract classes as interfaces to simulate ducktyping.

I'm trying to wrap my head around Concepts and Axioms using just the wikipage, but I'm failing at it, so far...
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5437 on: February 14, 2014, 11:50:05 am »

The simplified way of putting it is Concepts are interfaces for Templates, allowing you to say something along the lines of "Anything given to this function must implement the following functions...".

This means developers can easier understand what they have to give to a templated function, and also means compilation errors can be easier to read and more informative, instead of seeing "typename T in [fifty functions deep] does not have operator++()".

Plus you could probably overload on concept, meaning you can have templated functions that react intelligently at compile time depending on what functions are available. At the moment this is do-able (I've written templated functions that alter behaviour depending on if I can write the object to an out stream or not) but the syntax is pretty ugly.
« Last Edit: February 14, 2014, 11:51:50 am by MorleyDev »
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5438 on: February 14, 2014, 11:50:33 am »

The newest standard supports it in general doesn't it?  Auto types or something?
Nah, auto is compile-time and just make it easier because of not having to make long typedefs, or having to type weird long iterator names.

Ah, that's what I get for not Googling exactly what duck typing is (I was thinking it was type deduction).

I can agree that the way it's handled in many languages leaves something to be desired.  I code in JavaScript more than anything these days and use features like duck typing all of the time.  I also waste a lot of time fixing bugs that are related to them.  There's a trade off between being able to code "efficiently" and safely I suppose, and JavaScript has precious few ways to enforce constraints on code...

Quote from: MorleyDev
Most of the new C++11/14 language features are either things that have been tried and tested and proved pretty damn useful in other languages (type deduction, yay! lambdas, yay!) or things to do with metaprogramming to simplify that whole mess (variadic templates, yay! constexpr, yay!). I now consider C++ a more syntaxically modern language than Java, which is only just getting Lambdas next month and still no type deduction because reasons -_-

Lambdas are an important feature and something I'm happy to see in C++ now.  The syntax I was not thrilled with, but that's not my decision.  :)  The other things I guess don't impress me too much because I don't use complex templates in C++ really ever.
Logged
Through pain, I find wisdom.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5439 on: February 14, 2014, 11:59:13 am »

Yeah, ideally you won't need the template stuff. But the libraries you'll use most likely will, when you consider how much boost has had to hack around in the past it's amazing it's took this long. Faster compile times and simpler interfaces for those libraries is a godsend.

And then you get things like http://banditcpp.org/, which is so much prettier than older testing libraries like CppUnit and GTest...

The syntax for lambdas isn't the nicest because of that damned [], but it makes sense since C++ has need of much stricter scoping rules, since you could want to take something by-value or by-reference and the compiler needs to know which.

C++14 is cleaning it up, allowing for something like: "[](auto x) { return x * 2; }" to be valid. Which improves things like cpplinq incredibly,

Code: [Select]
auto data = cpplinq::from(cpplinq::range(1,100))
    >> cpplinq::where([](auto x) { return x % 3 == 0; })
    >> cpplinq::select([](auto x) { return std::make_pair(x, std::to_string(x)); })
    >> cpplinq::to_map();

auto keys = cpplinq::from(data)
    >> cpplinq::select([](auto x) { return x.second;  })
    >> cpplinq::to_vector();


So much easier than having to write the type for each parameter xD
« Last Edit: February 14, 2014, 12:59:40 pm by MorleyDev »
Logged

ECrownofFire

  • Bay Watcher
  • Resident Dragoness
    • View Profile
    • ECrownofFire
Re: if self.isCoder(): post() #Programming Thread
« Reply #5440 on: February 14, 2014, 07:09:17 pm »

Duck typing simplifies a lot of things, yes.
C++ has duck typing too with templates :P

I really hope this was a joke.

Nope, it's just the difference between static and dynamic typing.

In Python and many other languages (Lua, JavaScript...) you can write something like duck.quack() and as long as duck is an object with the function quack(), it will work just fine.

Now in C++, you could do it with a template. But even without templates you could write auto duck = functionThatReturnsAnObject(); duck.quack();, and it will work for any object that has the appropriate method. This is a bit different in that it errors at compile-time instead of at run-time, but again that's just the difference between dynamic and static typing. This is especially true with operator overloading. For example, you could overload the * operator in std::string for int to get multiplied strings.

auto is basically just type-deduction. If a function returns some really long name with template parameters and iterator types (like std::unordered_map<size_t, std::string>::iterator or something) then you can just type auto it = someMap.begin(); and not have to type it out. Eliminates the need for typedefs in those situations as well, which is nice for code clarity. Modern C++ guidelines say to use it liberally.
« Last Edit: February 15, 2014, 02:00:17 am by ECrownofFire »
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5441 on: February 14, 2014, 08:50:37 pm »

Using auto for template types seems like a pretty reasonable thing to do.  I assume it can be used for anything though, so I wonder how many programs will suddenly have 95%+ of their variables declared as auto and leave it up to the maintaining programmer to figure out what they really become.  In many cases it should be pretty obvious I guess, but I wonder how the compiler decides what type to assign to something if multiple types are valid?
Logged
Through pain, I find wisdom.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5442 on: February 14, 2014, 08:55:27 pm »

I don't think there are any situations where C++ allows ambiguity on return type. But essentially for auto the same rules as template parameters apply.

Considering good tooling lets me instantly see a type by hovering over the declaration or just hitting "." and seeing what functions are available, maintaining statically typed languages that use type deduction is actually incredibly easy. I'd argue easier, since you have less information being repeated so less of a cognitive burden. And given most IDEs with autocomplete for C++11 either are Visual Studio or use clang for tagging (which gives pretty much perfect autocomplete)...yeah. Only a problem if you use notepad, and then you get no sympathy from me :)
« Last Edit: February 14, 2014, 09:00:35 pm by MorleyDev »
Logged

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #5443 on: February 15, 2014, 10:37:47 am »

From now on, if anyone asks me which programming languages are the most friendly to new coders I'm just going to show them this article.

That pretty much sums it up.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5444 on: February 15, 2014, 10:55:27 am »

Swearing in commit messages is an integral part of the programming experience :P
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.
Pages: 1 ... 361 362 [363] 364 365 ... 796