Java 8 released


Recommended Posts

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#. 

More generally, I'd say it can help a lot with thinking in terms of data-parallelism and getting the programmer out of a sequential frame of mind.

Link to comment
Share on other sites

More generally, I'd say it can help a lot with thinking in terms of data-parallelism and getting the programmer out of a sequential frame of mind.

Yes, but even in sequential code, favoring pure functions has proved a very useful rule of thumb. I've often exposed existing bugs just by refactoring to use pure functions.

Link to comment
Share on other sites

Yes, but even in sequential code, favoring pure functions has proved a very useful rule of thumb. I've often exposed existing bugs just by refactoring to use pure functions.

Unexpected state: the cause of 99% of bugs (Don't quote me on that though)  ;)

Link to comment
Share on other sites

Even if the base framework doesn't support "HiDPI" you can always correct that through code.

Lol look at their "better security": Enhanced Support for NSA Suite B Cryptography

 

java is ####ing disgusting...

Research what it actually is before jumping to conclusions, because Suite B covers AES/ECDHE/SHA2, which are all really good and secure.

Link to comment
Share on other sites

It is nice to know that Java now has lambdas, but it is very late in the game.

Java has nothing to offer for me to switch from C# .NET, the only advantages are slightly more powerful generics and interfaces.

 

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

Well lambdas are split into two categories, (C# side)

1. Functions take in parameters, if any, and return something.

2. Actions take in parameters, if any, and return void.

Ability to create functions and actions with ease and little code overhead is excellent.

For example,

 

public abstract class IImage<T> where T : struct
{
	// other code
	protected IImage<T> _mathOp(Func<T, T> _func, bool _parallel)
        {
            if (_parallel)
            {
                Parallel.For(0, this._data.Length,
                    i => this._data[i] = _func(this._data[i])
                        );
            }
            else
            {
                for (int i = 0; i < this._data.Length; i++)
                {
                    this._data[i] = _func(this._data[i]);
                }
            }

            return this;
        }
}
Note that I use a lambda (Action<int>) which accepts index i as input for parallel for loop.

Then I can just use that function, like so,

 

public class ComplexImage : IImage<Complex>
{
	// other code
		
	public override IImage<Complex> Log10(bool parallel = true)
        {
            return _mathOp(Complex.Log10, parallel);
        }
		
	// Complex.Sin, Complex.Cos, Complex.Tan, Atan, Sqrt, Exp...
}
Just one line of code. No need to create a class implementing an interface with

"public Complex Math(Complex c);" and pass it in.

Another example,

        public static IImage<Complex> Add(params IImage<Complex>[] images)
        {
            return Run((a, b) => a + b, images);
        }

        public static IImage<Complex> Subtract(params IImage<Complex>[] images)
        {
            return Run((a, b) => a - b, images);
        }
Edited by _Alexander
Link to comment
Share on other sites

It is nice to know that Java now has lambdas, but it is very late in the game.

Java has nothing to offer for me to switch from C# .NET, the only advantages are slightly more powerful generics and interfaces.

 

Well lambdas are split into two categories, (C# side)

1. Functions take in parameters, if any, and return something.

2. Actions take in parameters, if any, and return void.

Ability to create functions and actions with ease and little code overhead is excellent.

For example,

 

public abstract class IImage<T> where T : struct
{
	// other code
	protected IImage<T> _mathOp(Func<T, T> _func, bool _parallel)
        {
            if (_parallel)
            {
                Parallel.For(0, this._data.Length,
                    i => this._data[i] = _func(this._data[i])
                        );
            }
            else
            {
                for (int i = 0; i < this._data.Length; i++)
                {
                    this._data[i] = _func(this._data[i]);
                }
            }

            return this;
        }
}
Note that I use a lambda (Action<int>) which accepts index i as input for parallel for loop.

Then I can just use that function, like so,

 

public class ComplexImage : IImage<Complex>
{
	// other code
		
	public override IImage<Complex> Log10(bool parallel = true)
        {
            return _mathOp(Complex.Log10, parallel);
        }
		
	// Complex.Sin, Complex.Cos, Complex.Tan, Atan, Sqrt, Exp...
}
Just one line of code. No need to create a class implementing an interface with

"public Complex Math(Complex c);" and pass it in.

Another example,

        public static IImage<Complex> Add(params IImage<Complex>[] images)
        {
            return Run((a, b) => a + b, images);
        }

        public static IImage<Complex> Subtract(params IImage<Complex>[] images)
        {
            return Run((a, b) => a - b, images);
        }

Ah okay.  I have a feeling I am going to need to read into this.   I have never had to deal with programming like that.  Been programming more or less the same for the past 4 years at my job.  Parallel computing and advanced math is something that's never been an issue.  For threads I just use either a thread or background worker and all is taken care of.   However I can definitely see where knowing parallel computing, functional programming etc, can be good to know.

Link to comment
Share on other sites

This topic is now closed to further replies.