Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
hardyp180
Active Contributor
Most ABAP programmers are terrified of JavaScript or indeed any other programming language than ABAP. They are also scared of being run over by a huge ship. Can an SAP Press book on JavaScript help address this fear? PART TWO!


JavaScript Book


To recap I have already written a blog regarding my initial thoughts after reading the very start of this book.

https://blogs.sap.com/2022/09/10/javascript-book-review-part-01/

And just to be clear, this is the book we are talking about: -

https://www.sap-press.com/javascript_5554/

And this is how to avoid Huge Ships: -

https://www.amazon.com/Avoid-Huge-Ships-John-Trimmer/dp/0870334336

Comments Sense

I would just like to start by addressing some concerns raised in the comments from my original blog. The first being that there are already half a million JavaScript books out there so what is so special about this one?

Well, nothing really - except SAP Press gave me a free copy to review! Being a bit more sensible for a second – very difficult for me – I understand that this is not a “new” book as such, because it has been available in the German language only for the last half a million years. It was such a best seller in that environment that SAP Press decided why not translate it into English and see what happens?

Jelena mentioned that this is a huge book – 1000+ pages – and that might scare some people off. This is especially true in the “Tik Tok” world in which we live where people’s attention spans have gone down to 3.5 seconds.

On the B side a lot of ABAP programmers are used to SAP Press and since this book has the same “look and feel” as existing SAP Press books maybe that will somewhat lessen the fear of the unknown. I love huge books myself e.g., Lord of the Rings. Much better than the huge ships that run you over.

Known Unknowns

Just to re-iterate the idea is to become a “full stack of pancakes” developer – that is you not only understand the back-end ABAP code (model) but also the front end UI5 code which is written in JavaScript (controller). The “view” is written in XML and is not supposed to have any “smarts” at all (some may argue with that, but that is the official SAP position).

In any event since all the new SAP programming models revolve around UI5 if you can become conversant with both ABAP and JavaScript then you can instantly earn one hundred times your current salary plus all your romantic fantasies will come true overnight. And you will be knighted by King Charles III, and you will find a way to bring about world peace and solve the environmental crisis.

That sounds good does it not? So why doesn’t anybody do it? Amazingly – and this is something I constantly struggle to understand why this is the case – ABAP programmers seem to be saying “I am far too stupid to learn more than one programming language”. They seem to believe this and tell this “Fact” to management, who believe them, and this turns into a self-fulfilling circle.

If you think about it the whole thing is nonsense. I spend a lot of time in hotel rooms on business travel and no two hotel rooms have a shower that works in remotely the same way. You don’t find me refusing to have a shower in a hotel room because the controls are different to what I am used to in the flat where I normally live. And I must work the controls without my glasses on, so I am effectively blind. It does not stop me.

The fact is that no ABAP programmer is too stupid to learn another language – after all they learned ABAP! You don’t have to read the book I am talking about, or buy any book, there is loads of stuff on the internet. You do have to make a microscopic amount of extra effort outside of work. Even if it is only five minutes a week, it is five minutes more than most people do as they do not have the time as they are far too busy playing video games or hurling abuse at other people on assorted Social Media platforms.

In fact, one piece of advice given to programmers in general is to learn one new programming language every year. It is not as if there is a shortage of them, or a shortage of new ones coming out each year. I was once told to learn LISP as then even if you never used it in real life, you would never look at a programming problem the same way ever again. I did in fact read a book on the language and it made my brain go even weirder than it was before, which I would have thought was impossible.

JavaScript Tease

I will come back to talking about JavaScript in a minute but first some important news. For some time now I have been asking people to solve the mystery of who killed Count Dracula and one gentleman in India correctly identified the murderer. He was the only one to do so and thus got all the prizes. Here they are having made there way safely from Australia to India.


Prizes in India


The Monster who killed Count Dracula had the super-power of making the sun shine in the middle of the night, which is really useful when you are fighting vampires. Obvious really in retrospect but the clues were all there and only one person in the world worked it out.

Moving on, I had hoped to write another JavaScript blog before now, but I am always doing about twenty-three million different things at once. Currently I am writing an online course for “Michael Management” about exception handling to go along with the one I did about Test Driven Development.

Now you might think that exception handling is the most boring topic in the universe but in real life 90%+ of code should be dealing with the “unhappy path”. Some programmers just do not bother until you get dumps in production or complaints but in fact building in proper error handling using exception classes can be a fun thing to do, just like TDD. I know that sounds crazy, but it is true. Possibly my idea of fun is not your idea of fun.

Present Arms

In addition, I have just read a small book called “Deliver Unforgettable Presentations”

https://www.amazon.com/Deliver-Unforgettable-Presentations-Remembered-Person/dp/1957651067


Unforgettable Presentations


I will probably re-read that one several times. I saw Darren LaCroix live in a Toastmasters event in Australia and I am aware (and it is mentioned many times in the book) that Patricia Fripp is the sister of Robert Fripp from “King Crimson”.

My dream is to go to an SAP event where every single presenter takes the “Toastmaster” thing seriously and delivers a knockout speech. I try to do this, but it is always a work in progress but at least I am trying. Lots of people think technical knowledge is enough and then are shocked when they have slides with ten million words and read the words out and the audience falls asleep or kill themselves. Just to end the agony. I will say this again because I cannot say it enough – if you are giving a presentation either in public or at work and you read out your slides then you are inflicting unbearable torture on your audience. They will not thank you for it. A human brain can only do one thing at a time – read the slides or listen to you. If you have a slide with lots of words, the audience will read those words and not listen to you at all – you could be making farmyard animal noises and the audience would not notice.

At Long Last – JavaScript!

OK – I just had two four-hour train trips and used that time to read some more of that JavaScript book I am supposed to be reviewing.

As I may have mentioned before what I am tempted to do is to list every new thing I learn but that would not be very good news for SAP Press as then there would be no need for anyone to buy the book as I would have given everything away So I just trying to give a general idea by picking a small percentage of new things I learn. So – off we go…

In all the examples I first saw of writing code inside an HTML file (at SAP TechED) back in 2001 your just wrote the code inside the HTML file, which works. I am happy to learn that is a Bad Thing as it mixes two different things (structure of a web page and behaviour of a web page) together. A breach of the Single Responsibility Principle. Instead, the idea is that HTML file just does a callout to the file where the JavaScript (or whatever) code lives.

Let It Be

In 1981 when I was learning BASIC so I could program the ZX81 computer I had been given the very first line of code I had ever seen was thus

LET X = 1

In other words, a new variable called “X” is created and it has the value of “1”. Well guess what? It is 2022 and if you write the exact same code in JavaScript, you get the exact same result. So – how difficult was that for me to get my head around? Not very - in both 1981 and 2022.

The Text Best Thing

One thing that has always puzzled me is when I look at the SAP ABAP code written by our consultants from the 1999/2000 period most of the currency/quantity/numeric fields are all defined as characters or NUMC. I can only presume that the idea of having specific data types for numbers is rather recent.

So, I was not totally shocked when one of the first JavaScript examples had you entering two numbers into text fields, which were then added together and the result output into a third text field.

Strictly Come Dancing

In ABAP the rules for the syntax inside methods are stricter than the rules inside FORM routines e.g., methods do not allow header lines on internal tables. Moreover, in higher ABAP releases you can specify what rules a program you are creating should follow e.g., should it be compatible with ABAP in the Cloud.

It turns out you can specify “strict mode” in JavaScript as well at the start of a file or a function within that file and that disallows older obsolete syntax. The point I am making is that things are not that different in JavaScript world than in ABAP world, and I am going to keep making that point again and again. So here comes another one.

Chain of Fools

In ABAP you can “chain” several statements together e.g., write DATA: and then declare a whole bunch of variables and then not have to write DATA in front of each one. Well guess what? You can do the same in JavaScript.

Word Up

The guy who first taught me ABAP in Israel said the strangest thing about ABAP is you can declare a variable with the same name as a keyword. For example, I could declare a variable called LOOP or DATA and ABAP would be fine with that. Lars H has shown some examples whereby changing the name of a variable to a keyword (like naming a variable DATA for example) can change the behaviour of subsequent ABAP code. Obviously, that is BONKERS.

Other languages, like JavaScript, do not let you do this.

Ironically if you have a burning need to use a variable name like DOCUMENT or LOCATION in your JavaScript code maybe one way to get around it is to use a Hungarian Notation Prefix. But maybe that is not a good idea.

Less is More

The list of keywords is much smaller than the list in ABAP. I don’t know if that is good or bad – you could argue that if you can do everything you need with less keywords that is good, or you could argue that lots of keywords make it clearer what you are doing.

What is clear is that as time goes on more and more keywords from languages like JavaScript are finding their way into ABAP e.g., REDUCE and INSTANCEOF. I just hope those keywords do the same thing in ABAP as they do in the original language otherwise people are going to get really confused.

The INSTANCEOF is interesting – in ABAP that lets you know the concrete class of an object instance. It could be argued that is against the LSP (the L in SOLID) which says that the caller should be totally unaware of the concrete class because it should not matter HOW the class works only WHAT it does. I am wondering if this functionality is more important in untyped languages like JavaScript.

Tubbs! Crockett! You are Off the Case

As you know in ABAP you name variables with underscores like NO_OF_BIG_MONSTERS whereas in other languages the name would be “noOfBigMonsters”. The latter is called “Camel Case”. I had known that for a while but never knew why. Apparently, it is because all the capital letters at random intervals look like the humps on a camel. In the example above the camel would have had three humps. I tend to think the more that code looks like plain English the better and so I tend to favour the underscores, but ABAP is very alone in this regard.

He Likes to Keep his Fire Engine Clean – It’s a Clean Machine

I may have already mentioned this, but once I have finished reading (and reviewing) this book then the next book off the rank is the “Clean JavaScript” book. I read the “Clean Code” book by “Uncle Bob” many years ago and the “Clean ABAP” book, but I cannot really read the JavaScript equivalent until I am a bit more conversant in the language. That is as I said the basics were so easy to grasp, but you cannot really become a craftsperson at something until you understand the more complex elements.

You are not my TYPE!

Hopefully by the end of this book I can get my head around two seemingly opposing concepts. One the one hand it seems that if you have a variable in JavaScript that is a number – because you passed a number into it – and then at runtime you pass a string into it then that can cause all sorts of problems, because the type of the variable will change. I just cannot get my head around that – a loop, say, where a variable keeps changing from an integer to a string and back again. On the B side “Uncle Bob” keeps going on about how variables in JavaScript are immutable – that is as soon as you say the variable that stores the number of monsters is 5 then that is that it cannot be changed thereafter. Can you see the disparity here? Either a variable can be constantly changed at the most fundamental level, or it cannot be changed at all. Both concepts cannot be true at the same time. As Dire Straits sang “Two men say they’re Jesus – one of them must be wrong!”

He Shoots – He Scores! Period.

Here is a funny thing about ABAP. When it started there was no handling of decimal points. That is why working with VOFM user exits is so agonising, to this day. Since there was no concept of a decimal point then the idea was to have each ABAP statement end with a decimal point (a so called period). So, as we know – in ABAP - if you want to pass 0.5 into a packed number you must pass a string in, which is obvious madness. In JavaScript since you have a semicolon as the end of a statement you can pass 0.5 directly into your variable.

Next problem – in countries like the UK or the USA we use a comma to separate big numbers and a decimal point is used as a decimal point. e.g., 1,000,000.00. In Europe however a decimal point is used to sperate big numbers, and a comma is used instead of a decimal point e.g., 1.000.000,00

The standard SAP system can handle this – sort of – but as I have worked for a multinational company for so long it is painful to deal with this, especially with IDOCS. You end up with some users getting short dumps, and some not, depending on their user setting.

In JavaScript they get round this by specifying the number as 1_000_000. That way I suppose you do not upset anyone.

Put that in your Pipe and Smoke It

As you know in ABAP with the “new” syntax (which is not really that new anymore) you can write something like

MONSTER_MESSAGE = |Monster { MONSTER_NAME } is Coming to Get You!|.

Well guess what – in JavaScript this is pretty much the same but with a ` instead of a |, so that concept was probably copied straight from JavaScript to ABAP.

End of Part Two

By now you have probably got the general point I am trying to make. Many ABAP programmers are soiling their trousers every time they even think of writing in another language like JavaScript but as it turns out the more you investigate the language the more you find it is just like ABAP.

I will write another blog about this book in due course. I might do one on ABAP2XLSX first in an attempt to stop the one blog a month, every month, for the last ten years, on SDN which re-invents that particular wheel.

Cheersy Cheers

Paul
6 Comments
Labels in this area