Monday, April 27, 2020

A Look at GraphQL

REST is rather straight forward, has been around for a while and not a new buzzword. It is basically using http "verb" to do "CRUD" on your resource in URL. (where the verbs are POST, GET, PUT, DELETE), and "CRUD" being create-read-update-delete.

Straight forward (and relatively easy) is not good enough for some. It is not fast enough... suppose you want to get a list of people... and their friends... you would have to make http calls and combine results. Enter GraphQL. Nice presentation.

So this is like a little SQL language. Maybe worth incorporating to your work. Let's look at implementing... Alas how complex do you want to get? See https://www.graphql-java.com/tutorials/getting-started-with-spring-boot/#graphql-java-overview.

However I found this awesome simple example that I can actually even run: https://dzone.com/articles/a-beginners-guide-to-graphql-with-spring-boot. Thanks to DZone. The example I downloaded from github is very helpful.

Look, add a ton of complexity with big learning curve may not worth it... internally somebody still has to do the queries and somebody will need to parse that JSON... Use it only if you think it is worth it.

Friday, April 17, 2020

Python and math

Way back in college I was studying vector calculus.. the calculus of several variables and deal with functions like z = f(x,y).

One could graph it... using that Mathematica in the computer lab and back then only the experts (graduate students) know how to use it. Math software such as Mathematica and Matlab are there for a long time only academic research folks ever need to use them. I don't ever need to get my hands on it. My statistic knowledge is minimal... (3 quarters of mostly forgotten probability and statistics in college)

I studied some computer graphics... learned linear algebra tricks of collapsing 3D to 2D. That stuff I wouldn't call exactly easy. See here for a taste of it.

Python readily have this available with its Matlab package... and in just a few lines, I am able to make a 3D graph. See https://towardsdatascience.com/an-easy-introduction-to-3d-plotting-with-matplotlib-801561999725. I can even drag window around to see the graph in every angle!

This. is. neat.

Wednesday, April 15, 2020

Python: the BASIC of today

I took a look a Python a decade plus ago. At that time I kinda dismissed it as a toy language as I can do whatever I want in Java without learning another language which almost look just like it without braces.

Year after year if you look at list of popular languages you see Python on very top. See here for example. If you can still go to a bookstore or a library you see many children's book on programming using Python! ..and a lot of them focus even on creating your own games. There are endless camps luring parents to have them teach their kids Python (and charge you a hefty fee).

What makes Python so successful? It is easy to learn. Its got a shell you can run right away, no need to compile and link. It doesn't even require semicolons (but it uses a lot of colons). It comes with a rudimentary IDE called IDLE too. It is cross platform you can make Tkinter windowed apps and many other things. You don't even need to define your variables before you use it. Feels just like BASIC of the 80s.. except you can go crazy with GOTO statements in BASIC. In the 80s there is also the LOGO programming language which is also a Read-Eval-Print-Loop which is kinda fun because you can program that turtle and Python provides that too! There is even a game engine!

Well that appeals to students but what about professionals. It has many math and statistic packages ready to use for some powerful data analyzing. It even has machine learning things that can make "Data Scientists" job much easier. Syntactically it is quite C like except you spell out "and" "or" "not" instead of && || and !. But there are no bottoms of your blocks, indention is needed instead. It can handle lists and sets easily and not as clumsy as java. Given a couple days any C/C++/java developer can pick up its syntax. You can learn right from python.org, and W3Schools is one of many tutorial sites you can read about.

Howevver, it is usually interpreted (not compiled), that means there can be a performance issue and it can be a memory hog. And I really don't like using variables on the fly without even declaring (you can accidentally change a variable already in use too). Ok it can do desktop things what about the web? You CAN do web related stuff and will require extra package such as Django. And oh my gosh, I don't know why Microsoft embrace it so much in Visual Studio. It seems totally abandon its Visual Basic and endorsing Python. I generated a working website with Django like right away with its wizard... it even came with a login page. It works much like ASP/JSP.

Happy coding.

Newer Java

Java versions come so quickly it is hard to keep up. These days any language must have some sort of shell for REPL (Read Eval Print Loop). "jshell" is there since Java 9. I doubt anyone find that too useful.

I now have Java 11 (not even latest). And you can run your code even without compiling. And that deep down in everyone's heart everyone misses Pascal. now there is "var" to define variable without specifying the type just like many languages. Other dynamic typed languages like Javascript and Visual Basic has this for ages.

class Foo {
   public static void main(String arg[]) {
    var yes = true;
    System.out.println("Do you miss Pascal?"+ yes);
   }
}
I can run this with just "java Foo.java". I don't even need "javac" to compile it.

It compile behind the scene and does not even produce a .class file. This is a great write up of what's from 8 to 11. https://codete.com/blog/java-8-java-11-quick-guide/... but version 8 really was the major jump. Lambda and Streams and Optional stuff are just some of them. See here for a good list.