LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-11-2016, 06:30 PM   #16
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware FreeBSD Win10 MX
Posts: 9,658

Rep: Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085

Quote:
Originally Posted by Fat_Elvis View Post
Didn't mean to be critical, just humorous.

Eh, and I'd need one of those super wide screens to fit that in one line in a text editor. Hehe.
yeah but it is only one line, less time to read it, as apposed to two lines of code, causes it to run faster.
 
Old 12-11-2016, 06:35 PM   #17
Fat_Elvis
Member
 
Registered: Oct 2016
Distribution: FreeDOS 1.2
Posts: 252

Rep: Reputation: 73
Quote:
Originally Posted by BW-userx View Post
yeah but it is only one line, less time to read it, as apposed to two lines of code, causes it to run faster.
Hehe.
 
Old 12-11-2016, 06:36 PM   #18
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware FreeBSD Win10 MX
Posts: 9,658

Rep: Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085
Quote:
Originally Posted by Fat_Elvis View Post
Hehe.
Java Code
same thing,

Code:
public class ReferenceToStaticMethodExample {
     /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        List numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16);
        List primeNumbers = ReferenceToStaticMethodExample.findPrimeNumbers(numbers, 
                (number) -> ReferenceToStaticMethodExample.isPrime((int) number));
 
        System.out.println("Prime Numbers are " + primeNumbers);
    }
 
    public static boolean isPrime(int number) {
        if (number == 1) {
            return false;
        }
        for (int i = 2; i < number; i++) { if (number % i == 0) { return false; } } return true; } public static List findPrimeNumbers(List list, Predicate predicate) { List sortedNumbers = new ArrayList(); list.stream().filter((i) -> (predicate.test(i))).forEach((i) -> {
            sortedNumbers.add(i);
        });
        return sortedNumbers;
 
    }
}
 
Old 12-12-2016, 10:34 AM   #19
Fat_Elvis
Member
 
Registered: Oct 2016
Distribution: FreeDOS 1.2
Posts: 252

Rep: Reputation: 73
Quote:
Originally Posted by BW-userx View Post
Java Code
same thing,

Code:
public class ReferenceToStaticMethodExample {
     /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        List numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16);
        List primeNumbers = ReferenceToStaticMethodExample.findPrimeNumbers(numbers, 
                (number) -> ReferenceToStaticMethodExample.isPrime((int) number));
 
        System.out.println("Prime Numbers are " + primeNumbers);
    }
 
    public static boolean isPrime(int number) {
        if (number == 1) {
            return false;
        }
        for (int i = 2; i < number; i++) { if (number % i == 0) { return false; } } return true; } public static List findPrimeNumbers(List list, Predicate predicate) { List sortedNumbers = new ArrayList(); list.stream().filter((i) -> (predicate.test(i))).forEach((i) -> {
            sortedNumbers.add(i);
        });
        return sortedNumbers;
 
    }
}
Holy length of function names, there, Batman!

And I just re-noticed that they title says simplifying a script. Argh. Concentrating on things is a constant problem for some reason.
 
Old 12-12-2016, 11:15 AM   #20
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware FreeBSD Win10 MX
Posts: 9,658

Rep: Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085
Quote:
Originally Posted by Fat_Elvis View Post
Holy length of function names, there, Batman!

And I just re-noticed that they title says simplifying a script. Argh. Concentrating on things is a constant problem for some reason.
simplifying, being the key word here I suppose. so putting everything you can on one line is doing just that.

calling functions within functions within functions within functions etc...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash - simplifying an array Lucien Lachance Programming 15 08-02-2013 06:26 PM
[SOLVED] simplifying awk command froggins Linux - Newbie 5 02-24-2011 05:33 AM
Lighttpd URL simplifying alsharifhoussam Linux - Server 5 11-16-2009 08:20 AM
simplifying wine Four Linux - Newbie 6 12-28-2005 06:02 PM
Adding only new text/simplifying lists invisible_ink Linux - Newbie 1 11-24-2004 03:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration