Recommended Posts

well then. wasn't expecting that for another year or two. 

are there any major improvements from version 7?

 

mostly just use java for minecraft so only slightly interested

 

I found this post on reddit: http://winterbe.com/posts/2014/03/16/java-8-tutorial/

that's a decent tutorial on the JDK but i'm wondering from a general user perspective what's new & what's improved in the run-time environment (JRE)

Lambda expressions! 6 years after C# and 3 years after C++, but better late than never.

 

I think Scala will still make more sense for new development, but for legacy code having lambdas will make for nicer refactoring capabilities.

Having never used lambdas, what is the benefit?  I have read up on their use in C#.. but not sure where the benefit is.  It seems almost like it just replaces a function that could be cleanly written anyways?

Having never used lambdas, what is the benefit?  I have read up on their use in C#.. but not sure where the benefit is.  It seems almost like it just replaces a function that could be cleanly written anyways?

Lambdas are more than just functions because they capture all the variables in scope, so they're syntactic sugar for classes, not functions - that's actually what they compile to in C#. They're essential for programming in a functional style because they allow for easy creation and composition of functions. Usually classes in these languages occupy an entire file by themselves - reducing it to a single line enables very powerful techniques that would be awkward without!

 

If you haven't tried functional programming, you should check out F# (if you're on .NET) or Scala (for the JVM). http://www.tryfsharp.org/

Lambdas are more than just functions because they capture all the variables in scope, so they're syntactic sugar for classes, not functions - that's actually what they compile to in C#. They're essential for programming in a functional style because they allow for easy creation and composition of functions. Usually classes in these languages occupy an entire file by themselves - reducing it to a single line enables very powerful techniques that would be awkward without!

 

If you haven't tried functional programming, you should check out F# (if you're on .NET) or Scala (for the JVM). http://www.tryfsharp.org/

 

I think I understand.  I guess I just don't see why you would do like:

 

delegate int del(int i);
static void Main(string[] args)
{
    del myDelegate = x => x * x;
    int j = myDelegate(5); //j = 25
}
 

 

when you could either do:

 

static void Main(string[] args)
{
    int j = 5*5;
}

or

static void Main(string[] args)
{
    int j = square(5)
}

int square(int num)
{
   return num*num;
}

And achieve the same while being a little more readable.

 

Having never programmed functionally maybe I just don't understand it.   I'll take a look at F#.  In your opinion what makes functional programming beneficial / good?

that's a decent tutorial on the JDK but i'm wondering from a general user perspective what's new & what's improved in the run-time environment (JRE)

 

Maybe this: https://blogs.oracle.com/thejavatutorials/entry/jdk_8_is_released

I think I understand.  I guess I just don't see why you would do like:

 

delegate int del(int i);
static void Main(string[] args)
{
    del myDelegate = x => x * x;
    int j = myDelegate(5); //j = 25
}
 

 

when you could either do:

 

static void Main(string[] args)
{
    int j = 5*5;
}

or

static void Main(string[] args)
{
    int j = square(5)
}

int square(int num)
{
   return num*num;
}

And achieve the same while being a little more readable.

 

Having never programmed functionally maybe I just don't understand it.   I'll take a look at F#.  In your opinion what makes functional programming beneficial / good?

If the delegate is doing work in a separate thread, than you can deal with the separate thread as a single line (or two) instead of a separate class.

Having never programmed functionally maybe I just don't understand it.   I'll take a look at F#.  In your opinion what makes functional programming beneficial / good?

 

Well, let's take a simple example. Say you have a collection of numbers, and you want the sum of all even numbers in that list. With lambdas and higher-order functions, in a language like F#, you would do:

let sum = collection
          |> Seq.filter(fun n -> n % 2 = 0)
          |> Seq.fold (+) 0

In an imperative style, using C# for example, you would do:

int runningTotal = 0;
foreach(var n in collection) {
    if (n % 2 == 0) {
        runningTotal += n;
    }
}

There's a big conceptual difference between the two. The F# code is declarative: it states that we take a collection, take the elements divisible by 2, and "fold" (compute a single value) using the + operator and starting from 0. We are not stating how to perform this computation, we are stating what the computation is.

 

The C# code is all about implementation, state and control flow. We implement sum using a variable that holds the current state of the computation (runningTotal). We explicitely iterate over a collection, and alter control flow using an if statement to skip certain elements. 

 

This might not mean that much, until we run this over 1000000 elements doing a more complicated computation, and suddenly we'd like to run this in parallel to take advantage of our multi-core CPUs. Since the F# code states nothing about how the computation is performed, it's trivial to make it parallel:

 

let sum = collection
          |> PSeq.filter(fun n -> n % 2 = 0)
          |> PSeq.fold (+) 0

That's it, I changed 2 characters to use the Parallel Sequence module rather than the regular Sequence module. 

 

Because the imperative code is all about implementation, state and control flow, it would have to be changed dramatically to work with multiple threads.

 

Multithreading in imperative, object-oriented code is very hard, because it's difficult to reason about the order of state changes with concurrency; functional programming can help greatly because it favors pure (stateless) functions and a more declarative style.

 

Functional programming means functions that are more reusable, more obviously correct, easier to understand, easier to test, easier to parallelize, easier to compose, etc., etc. The advantages are many. http://fpbridge.co.uk/why-fsharp.html

 

Well, let's take a simple example. Say you have a collection of numbers, and you want the sum of all even numbers in that list. With lambdas and higher-order functions, in a language like F#, you would do:

let sum = collection
          |> Seq.filter(fun n -> n % 2 = 0)
          |> Seq.fold (+) 0

In an imperative style, using C# for example, you would do:

int runningTotal = 0;
foreach(var n in collection) {
    if (n % 2 == 0) {
        runningTotal += n;
    }
}

There's a big conceptual difference between the two. The F# code is declarative: it states that we take a collection, take the elements divisible by 2, and "fold" (compute a single value) using the + operator and starting from 0. We are not stating how to perform this computation, we are stating what the computation is.

 

The C# code is all about implementation, state and control flow. We implement sum using a variable that holds the current state of the computation (runningTotal). We explicitely iterate over a collection, and alter control flow using an if statement to skip certain elements. 

 

This might not mean that much, until we run this over 1000000 elements doing a more complicated computation, and suddenly we'd like to run this in parallel to take advantage of our multi-core CPUs. Since the F# code states nothing about how the computation is performed, it's trivial to make it parallel:

 

let sum = collection
          |> PSeq.filter(fun n -> n % 2 = 0)
          |> PSeq.fold (+) 0

That's it, I changed 2 characters to use the Parallel Sequence module rather than the regular Sequence module. 

 

Because the imperative code is all about implementation, state and control flow, it would have to be changed dramatically to work with multiple threads.

 

Multithreading in imperative, object-oriented code is very hard, because it's difficult to reason about the order of state changes with concurrency; functional programming can help greatly because it favors pure (stateless) functions and a more declarative style.

 

Functional programming means functions that are more reusable, more obviously correct, easier to understand, easier to test, easier to parallelize, easier to compose, etc., etc. The advantages are many. http://fpbridge.co.uk/why-fsharp.html

 

Ah okay.  So doing calculations and such makes a lot of sense to go with the Functional.  But would it be viable for like.. a forms style app, or game? Or is it meant more for computational style applications?   As for the lambdas I think I see the benefit.  A lot of it comes down to flexiblity, using different functions cross thread without issue.  Declaring on the fly functions and using them without needing separate code or redundant code.

Ah okay.  So doing calculations and such makes a lot of sense to go with the Functional.  But would it be viable for like.. a forms style app, or game? Or is it meant more for computational style applications?   As for the lambdas I think I see the benefit.  A lot of it comes down to flexiblity, using different functions cross thread without issue.  Declaring on the fly functions and using them without needing separate code or redundant code.

If your application consists mainly of boilerplate code like setting up forms and hooking up events, then there's not much that a functional language can do about it. You'll have the same boilerplate in a slightly different syntax. But if you have any sort of complexity beyond that then there's no doubt that at least being able to think functionally, regardless of language, helps tremendously. Few things have been as efficient in terms of improving my coding skills than learning a bit of F#. 

On the topic of functional programming in games, John Carmack has written a good article about how to apply functional techniques in C++: http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/

This topic is now closed to further replies.
  • Posts

    • well you can add a GPU for around $500, that's still around the price of Steam Machine but overall significantly better in performance.
    • Fresh CachyOS install with Niri - I guess it's a little orange, but I'm working on it
    • FastStone Image Viewer 8.5 by Razvan Serea FastStone Image Viewer is a fast, stable, user-friendly image browser, converter and editor. It has a nice array of features that include image viewing, management, comparison, red-eye removal, emailing, resizing, cropping, retouching and color adjustments. Its innovative but intuitive full-screen mode provides quick access to EXIF information, thumbnail browser and major functionalities via hidden toolbars that pop up when your mouse touches the four edges of the screen. Other features include a high quality magnifier and a musical slideshow with 150+ transitional effects, as well as lossless JPEG transitions, drop shadow effects, image annotation, scanner support, histogram and much more. It supports all major graphic formats (BMP, JPEG, JPEG 2000, animated GIF, PNG, PCX, PSD, EPS, TIFF, WMF, ICO and TGA) and popular digital camera RAW formats (CRW, CR2, NEF, PEF, RAF, MRW, ORF, SRF, ARW, SR2, RW2 and DNG). FastStone Image Viewer features: Image browser and viewer with a familiar Windows Explorer-like user interface Support for many popular image formats and PDF viewing True Full Screen viewer with convenient image zoom support and unique fly-out menu panels Crystal-clear and customizable one-click image magnifier Powerful image editing tools: Resize/resample, rotate/flip, crop, sharpen/blur, adjust lighting/colors/curves/levels etc. Eleven re-sampling algorithms to choose from when resizing images Image color effects: gray scale, sepia, negative, Red/Green/Blue adjustment Image special effects: drop shadow, framing, bump map, sketch, oil painting, lens Draw texts, lines, highlights, rectangles, ovals and callout objects on images Clone Stamp and Healing Brush Superior red-eye effect removal/reduction with completely natural looking end result Multi-level Undo/Redo capability Single click to switch between best fit and actual size mode Image management, including file tagging, rating and drag-and-drop to copy/move/re-arrange files Histogram display with color counter feature Compare images side-by-side (up to 4 at a time) to easily cull those forgettable shots Image EXIF metadata support (plus comment editing for JPEGs) Configurable batch processing to convert/rename large or small collections of images Slideshow with 150+ transition effects and music support (MP3, WMA, WAV...) Create efficient image attachments for emailing to family and friends Print images with full page-layout control Create fully configurable contact sheets Create memorable artistic image montages from your family photos for personalized desktop wallpapers (Wallpaper Anywhere) Acquire images from scanners. Support batch scanning to PDF, TIFF, JPEG and PNG Versatile screen capture capability Powerful Save As interface to compare image quality and control generated file size Run favorite external editors with one keystroke from within Image Viewer Offer portable version of the program which can be run from a removable storage device Configurable mouse wheel support Support themes (bright, gray and dark) Support dual-monitor configurations Support touch interface (tap, swipe, pinch) Support dual instances Play video and audio files (Third party codecs may be required for old versions of Windows) And much more... FastStone Image Viewer 8.5 changelog: Added support for SVG format Added Start importing automatically and Handle duplicate file names automatically options to the Import Photos and Videos tool WebP files can now be rotated and saved with a single click Enhanced dark theme support in the PDF viewer Fixed a bug where some links in PDF files were not clickable Other improvements and bug fixes Download: FastStone Image Viewer 8.5 | Portable | ~15.0 MB (Freeware) View: FastStone Image Viewer Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Rookie
      DaviKar went up a rank
      Rookie
    • Dedicated
      HidekoYamamoto94 earned a badge
      Dedicated
    • One Month Later
      timbobit earned a badge
      One Month Later
    • One Month Later
      nates earned a badge
      One Month Later
    • Week One Done
      Almohandis earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      462
    2. 2
      +Edouard
      160
    3. 3
      PsYcHoKiLLa
      111
    4. 4
      Michael Scrip
      85
    5. 5
      Steven P.
      69
  • Tell a friend

    Love Neowin? Tell a friend!