• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IDE Live templates vs functional language

 
Ranch Hand
Posts: 606
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I post here hoping is not such a stupid thing, I had to post on the beginning forum, because I am still missing some conceptual basic coding chunk.

Few people speak over the fact that Java is considered a language where there is much typing involved and that functional languages (ex Scala) are a great way
to deliver faster solutions in some cases. (Ok, there is also some consideration regarding a war deployment that in java can be heavy, or that one could be paid per line of code, and others ones)
While instead I noticed live templates are not used too much, almost all the tutorials I see on the internet do not mention them.
According to my experience using them spare a considerable amount of time and I am wondering if are underused.
I also understand that a functional paradigm is completely a different thing, but still I guess have to be really problematic to debug a functional language and mistakes that( I am guessing) could be more frequent( I am speaking of strongly typed languages). So I am wondering if a smart way to use templates could in some way counterbalance the need to use functional languages
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Live templates in an IDE like Eclipse are a matter of convenience. Yes, they save you from a lot of typing but unless you are writing an article about live templates, I doubt authors would want to muddy up the point they are trying to make about a programming concept by adding mentions of live templates in the mix. I could see maybe having a sidebar, like a separate box with a heading of "Tip For the Impatient Typist" but that still would seem a bit oddly out of place in an article about something like lambdas, for example.

As for functional programming and live templates, I don't see where you're making a connection. Sure languages like Scala cut down on the verbosity of Java and I'm sure there are code templates for common idioms in those languages. I guess that could help avoid basic logic errors but I fail to see the connection between the language being imperative or functional. In either paradigm, the programmer still has to think hard about how to express the solution as clearly and succinctly as he can. A convenience like a code template will only help you as much as a word processor helps you when you're writing a story by trying to guess what word you're trying to type and what word could come next, just as my tablet is doing as I type this reply. My tablet can't put together the whole reply for me though. I did that myself.

Does that make sense?
 
Giovanni Montano
Ranch Hand
Posts: 606
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:
As for functional programming and live templates, I don't see where you're making a connection. (cut..)
Does that make sense?


thanks. well they remain two distinct things, but the point is functional languages I am maybe wrongly assuming are preferred because permit to write faster code. And so do the live templates.
If the Java API developers would work to create some possibility to use live templates with muscles(although is an IDE thing, but this is the point..), maybe java could acquire eternal longevity instead to risk to become the next Pascal/Fortran. Decline that C or JS will never have.
I see you do Android. for instance there is a huge speak about dart and kotlin that could replace java, non only for copyright infringements but because are faster than java although I am not sure they are functional languages, but still make sense to see that the main cause java could be less prefered to scala, or even an OO lang not functional as phython is over time java takes for typing, or I am missing something?
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly do you mean by "faster"? Is that in terms of physically typing out of characters on the keyboard? Or is it in terms of producing something that works in a shorter amount of time? There may be some connection there but not in the way I think you're taking it.

The major part of software development is not in the typing. It's in the thinking.

Functional programming language constructs allow you to think at a higher, more abstract level. When you're thinking at that level, you don't have to worry about low-level details like loops, counters, incrementing, or even things like concurrency. You think about the goal, what you want to accomplish in the end. That's really where functional programming is attractive.

There are other considerations, too. Because functional programming constructs favor immutability, this opens up opportunities to parallelize processing, distributing a task across multiple cores or even across machines, for example. This is transparent to the programmer. He just defines what the task is and basically lets the platform/framework take care of the nitty-gritty details of figuring out how to parallelize. New features in Java 8 like the Streaming API allows you to do that as well. The program code may still not be as concise as their equivalents in Scala but they do come pretty close.

Bottom line, I see a very tenuous and shallow correlation between code templates and the ability to write abstract, goal-oriented code in functional languages like Scala or even similar constructs that you can do in Java 8 versus more imperative code that has a tendency to be cluttered with implementation details like looping, branching, and threading.

 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are comparing apples and oranges here, Giovanni. Functional programming is not just a way to write less code, although that can be one of the benefits of using FP with the right language. It's not about static or dynamic typing either, as static typing in any language can help to trap certain errors at compile time so you can fix them before your users see them at runtime. Scala has static types, while Clojure does not, yet Clojure is probably more of a "pure" FP language than Scala, which is a hybrid FP/OOP language.

Immutability is a key FP feature that really helps to reduce errors, which is why people like Josh Bloch (in "Effective Java") also recommend making variables immutable in Java where appropriate. All "variables" are immutable by default in both Scala and Clojure, for example, so you have to deliberately choose to create a risky mutable variable in these languages, and you rarely need to do this in an FP language compared to OO.

Having functions as first class objects, and being able to use higher order functions, removes a lot of complexity and eliminates the need for many common OO design patterns (see https://pragprog.com/book/mbfpp/functional-programming-patterns-in-scala-and-clojure), because you no longer need to wrap a function in a load of extra kruft just to pass some behaviour into another function (method). Java 8 lambdas finally give you the ability to do this in Java, but it's still pretty clunky compared to Clojure or Scala.

OOP and FP take different approaches to how you combine data and processing to implement your task. Objects combine state and behaviour and try to encapsulate complexity, often resulting in lots of different structures (classes) with distinctive behaviours. FP tends to aim for relatively simple data structures and separate functions, plus things like collections that provide fairly generic mechanisms such as map() and reduce() (i.e. higher order functions) for applying those functions to the data. There's a whole world of mathematics behind this, which I do not understand, but that's OK with me right now.

Of course, purists on both sides will argue all day about which is best, and I'm no expert on either paradigm, so this is a very simplistic view. But as an ordinary developer who's worked with procedural, imperative, declarative, OO and FP languages, I find FP much easier to work with (even if I still don't understand monads!), because I find it allows me to focus more clearly on telling the computer what I want to do, instead of having to tell it how to do it, and I can do what I want with less code than in Java. FP works for me.

YMMV, of course!
 
chris webster
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java will be around for a long time yet, even if it will be sharing the JVM with other languages in future. Different languages offer different advantages/disadvantages in different contexts. I like Scala for Big Data work, for example, but Python for scripting and quick prototyping. You pick the tool to suit the job, and plenty of people will be using Java for many years to come.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Bottom line, I see a very tenuous and shallow correlation between code templates and the ability to write abstract, goal-oriented code in functional languages like Scala or even similar constructs that you can do in Java 8


Where I see code templates coming in is in relieving programmers, especially those like me who can't remember all the right incantations, from having to remember exactly how to string up the different calls and transformations. I can see myself defining a code template for a "filter-map-sort-collect" incantation and that would save me some time and effort. Then I may want to have another that includes parallelization. The time savings there are minimal, IMO, and really have a lot to do with dealing with my laziness and forgetfulness rather anything with the programming paradigm.
 
Giovanni Montano
Ranch Hand
Posts: 606
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for your precious explanations.

Possibly my curiosity cames out from android studio as it collapses automatically the inner classes in lambda expressions. So that I thought live templates could allow the kind of easy focus design approach quoted above of implementing immediately our own train of thoughts without strictly thinking to right variables, loops etc
but evidently I am completely wrong, thank you again for the nice insights and patience.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Giovanni Montano wrote:
Possibly my curiosity cames out from android studio as it collapses automatically the inner classes in lambda expressions. So that I thought live templates could allow the kind of easy focus design approach quoted above of implementing immediately our own train of thoughts without strictly thinking to right variables, loops etc.


Those are nice features of the IDE that can assist you in focusing your attention where you need to. That has very little to do with the programming paradigm though.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic