Learning programming languages *split*

Discussion in 'General Discussion' started by tuna, Nov 25, 2016.

  1. entity279

    Veteran Regular Subscriber

    Joined:
    May 12, 2008
    Messages:
    1,217
    Likes Received:
    409
    Location:
    Romania
    x = x +1 - this is a mathematical nonesense but widely used when teaching programming (of course due to being a notation supported by mainstream - old and new - languages)

    When one approaches functional programing, habits such as using mutation must be abandoned. Hence why it may be more dificult

    I also agree that it is actually easier as the handling of state the FP way results in programs that are easier to maintain and debug.

    But there are "degrees" with regrads to functional programming. It is one thing not to use side effects and pass functions as objects. it is another to design APIs as algrebras, master recusion schemes, and to see Adjoints and coproducts everywhere. The latter involves quite a bit of study, and I'd argue that is more involving thatn your avereage design pattern, being more abstract.
     
  2. Arwin

    Arwin Now Officially a Top 10 Poster
    Moderator Legend

    Joined:
    May 17, 2006
    Messages:
    17,672
    Likes Received:
    1,192
    Location:
    Maastricht, The Netherlands
    Sure but where those are used, you are often looking at a mathematician at work, not necessarily a programmer who thinks Domain Driven Design and code readability are priorities!
     
  3. entity279

    Veteran Regular Subscriber

    Joined:
    May 12, 2008
    Messages:
    1,217
    Likes Received:
    409
    Location:
    Romania
    I'd argue that these vastly empower programmers regardless.

    All these concept don't come from matematics as a whole, but from a portion of it, cathegory theory. Cathegory theory is mearly a language used to describe laws and structures, but with no meaning intrinsec (abstract nonsense).
    Which is , oftentimes, exactly what programing is about - applying structures and flows to various domains (sales, games, computer aided design)
     
  4. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    14,711
    Likes Received:
    2,166
    then dont differentiate with capitals.
    NameOfObjectAmount = amount
    instead of
    Amount = amount

    for example

    modern ide's come up with a list when you type the first few letters so you only have to actually
    type NameOfObjectAmount once, so theres no reason not to use long descriptive variable names
     
  5. Cyan

    Cyan orange
    Legend Veteran

    Joined:
    Apr 24, 2007
    Messages:
    8,525
    Likes Received:
    2,239
    got the book! It is in beta state, latest release being in September. The first 50 pages of Domain explanation save for the UML at the beginning sounds unfamiliar to me, but then the F# part looks fine even for a beginner. However, in that sense the Book of F# is what I am reading and I am going to keep it reading it til there is some advance on my part.

    oh well, I meant when it comes to objects at declaration time Car car("whatever comes here") = new Car();

    On a different note, kinda off-topic I got the Roland Sound Canvas VA (I remember the conversation about MIDI with you but I can't recall in which thread it was) and the sound is awesome, especially the native GS files...wow... I have the Roland SD-50 and it's good but it's mostly a GM2 synth, GS sounds quite basic in it.
     
  6. Cyan

    Cyan orange
    Legend Veteran

    Joined:
    Apr 24, 2007
    Messages:
    8,525
    Likes Received:
    2,239
    Making a platformer in F# with monogame:

    https://bruinbrown.wordpress.com/2013/10/06/making-a-platformer-in-f-with-monogame/

    I am also following the development of another functional language, also open source, called F* (which stands for F Star). It seems a lot to learn, but the idea is that when you know how to program in OO mode, or functional programming, what changes for the most part is the syntax.

    https://www.fstar-lang.org/

    Some interesting tidbits:

     
  7. Rodéric

    Rodéric a.k.a. Ingenu
    Moderator Veteran

    Joined:
    Feb 6, 2002
    Messages:
    3,965
    Likes Received:
    825
    Location:
    Planet Earth.
    How fast is F#, I'm programming in C# and even using unsafe & after a couple of hours I just couldn't match C++ speed, C# being an order of magnitude slower after optimising... :(
    I just can't use something that slow, it means its wasting valuable CPU cycles therefore energy uselessly...
     
  8. Arwin

    Arwin Now Officially a Top 10 Poster
    Moderator Legend

    Joined:
    May 17, 2006
    Messages:
    17,672
    Likes Received:
    1,192
    Location:
    Maastricht, The Netherlands
    What are you comparing to what?
     
  9. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    14,711
    Likes Received:
    2,166
    and what are you writing cpu's can execute millions of instructions per second
     
  10. zed

    zed
    Veteran

    Joined:
    Dec 16, 2005
    Messages:
    4,379
    Likes Received:
    595
    Sure C# is slower but surely not 10x slower, one thing I'ld like done with C# is ability to disable GC and ability to call it only when I want it called. Still C# is my fav language
     
    Cyan likes this.
  11. Cyan

    Cyan orange
    Legend Veteran

    Joined:
    Apr 24, 2007
    Messages:
    8,525
    Likes Received:
    2,239
    some stats on how slower it is would be good to know... C++ is faster overall, they say, that's whey they use for AAA games. But not orders of magnitude faster, and you can produce very fast code with C#, also in games --Ori and the Blind Forest and Cuphead come to mind, which are programmed using Unity and C# and don't require a very powerful machine.

    When I started to become interested in functional programming and learnt about Haskell (that'd be a great language to learn, however if I had to learn it I'd do it for academic reasons, because what makes F# stands out compared to it, is that it has good tools and a good ecosystem around, which many of those languages lack, imho) :) and F#, I was also interested in knowing which one is faster. Most of the replies I remember to that stuff pointed out at F# being faster.

    People mentioned the fact that F# is faster than C#, maybe because you can express most of the same functions in less code and maybe while the computer is doing basically the same, the programmer's mind is freed from some extra steps to take and can think better and clearer on what code to use. :)

    However, as of now, C# compiler -given the fact that the language is more popular- has gone through more some extra refinement that F# is lacking. afaik, for instance, when it comes to UWP, C# has access to a mode where the code runs much faster and is better optimised when you program a Windows store app, wp app, or Xbox app -UWP-. This is quite recent and it's still not present in F# but they will add that support in the future.
     
  12. Cyan

    Cyan orange
    Legend Veteran

    Joined:
    Apr 24, 2007
    Messages:
    8,525
    Likes Received:
    2,239
    #152 Cyan, Nov 10, 2017
    Last edited: Nov 10, 2017
    Arwin likes this.
  13. pcchen

    pcchen Moderator
    Moderator Veteran Subscriber

    Joined:
    Feb 6, 2002
    Messages:
    2,735
    Likes Received:
    100
    Location:
    Taiwan
    Modern programming languages do have some extra costs that does not appear in C/C++. For example, many modern programming languages require boundary check on all array access, and while it could be optimized away sometimes, it still makes array indexing more expensive.
    Indirect object referencing is also much more common in modern programming languages than in C/C++, although it's not as slow. Indirect function call (which is generally slower than direct function call) is also very common in modern programming languages but relatively rare in C/C++.

    The good news is that many programs with tight loops can actually be moved to the GPU, which normally uses a C/C++ like programming language.
     
    Cyan likes this.
  14. Arwin

    Arwin Now Officially a Top 10 Poster
    Moderator Legend

    Joined:
    May 17, 2006
    Messages:
    17,672
    Likes Received:
    1,192
    Location:
    Maastricht, The Netherlands
    There are a lot of gotcha’s too, like strings being immutable in C# and mutable in C++, which is why I was asking Roderic what he was comparing. It is a really obvious one to most but using Stringbuilder, meant for string operations, is really orders of magnitude faster.

    Where F# normally wins against C# is type checking: it can do much more of that at compile time which saves time on runtime. Also some things you have to do differently to be fast - a loop in F# is fastest in a tail end recursive function, at which point it is 25%-30% faster than in C# I believe.

    And of course managed code, running against a VM and running against .NET framework all come at penalties, so you have to make sure you compare like for like.

    No doing async and parallel work is never easy, but in F# it is certainly more elegant than in almost any other language I know of!
     
    Cyan and BRiT like this.
  15. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    14,711
    Likes Received:
    2,166
    Why would you want to run code in a vm especially as your complaining about speed?
     
  16. Arwin

    Arwin Now Officially a Top 10 Poster
    Moderator Legend

    Joined:
    May 17, 2006
    Messages:
    17,672
    Likes Received:
    1,192
    Location:
    Maastricht, The Netherlands
    Not that kind of VM. Just in Time / JavaVM kind of ...
     
  17. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    14,711
    Likes Received:
    2,166
    Ok why would you want to run code in a different kind of vm ?
     
  18. mrcorbo

    mrcorbo Foo Fighter
    Veteran

    Joined:
    Dec 8, 2004
    Messages:
    3,544
    Likes Received:
    1,956
    Ease of distribution. One binary runs on any device capable of running the VM.
     
    BRiT likes this.
  19. tuna

    Veteran

    Joined:
    Mar 10, 2002
    Messages:
    3,107
    Likes Received:
    344
    Garbage collected languages are crap for games because they are very inefficient when it comes to memory access patterns (which is what usually takes most times in games and HPC-type programs) and are very indeterministic (the GC might run in one frame but not the other). Rust and modern C++ are better for games.
     
  20. Cyan

    Cyan orange
    Legend Veteran

    Joined:
    Apr 24, 2007
    Messages:
    8,525
    Likes Received:
    2,239
    Want to make special mention to the resources the guy from the F# Delight video recommends to learn the language (gotta get those books, plus they are from the 4 version of the language, which means pretty recent) by the very end of the video:

    http://fsharpforfunandprofit.com/

    The book Beginning F# 4.0 from Kit Eason. Probably better than the book of F# for beginners?

    http://www.apress.com/us/book/9781484213759

    [​IMG]

    When you learn the basics well, this is the expert book he recommends. The book was partially written by Don Syme.

    http://www.apress.com/us/book/9781484207413

    [​IMG]

    Kit Eason's courses on PluralSight:

    https://www.pluralsight.com/courses/fsharp-jumpstart

    You can try HackerRank challenges in F#:

    https://www.hackerrank.com/
     
Loading...

Share This Page

  • About Us

    Beyond3D has been around for over a decade and prides itself on being the best place on the web for in-depth, technically-driven discussion and analysis of 3D graphics hardware. If you love pixels and transistors, you've come to the right place!

    Beyond3D is proudly published by GPU Tools Ltd.
Loading...