Showing posts with label object-oriented. Show all posts
Showing posts with label object-oriented. Show all posts

Monday, 29 April 2024

What's the best programming language for beginners?

What should be a programmer's first language?

Often, this is not a deliberate choice, more a matter of circumstance. Perhaps a programmer started on QBasic as a kid. Perhaps, like me, the programmer picked it up in school and was made to learn C++ or Java. I would even venture to say very few programmers start out saying I'm going to begin my programming journey with the best, most modern language out there! To begin with, how would they know what constitutes the "best" programming language, or what even is a good programming language? You don't know what you don't know, after all.

Let's learn!

Also, how suitable a programming language is for your purposes also really depends on what your purpose is. Do you want to crunch data? Write games? Build web portals?

So, obviously, before we can sort out what the "best" programming language is, perhaps it is more useful to figure out what a programmer's first programming language should be. After all, this choice opens different doors.

For that, we should probably look at a few factors. I can only draw upon languages I've coded in before. as examples, obviously.

Syntax

For this, we look at simplicity of writing code in that language. How intuitive the syntax is, and how few extra keystrokes needed to get something done.

For this, my obvious picks would be Python or Ruby. Less of the semi-colons and curly brackets. Anyone picking either Python or Ruby as a first language, I suspect, would be less likely to give up out of frustration.

Code syntax.

C# and Java is probably among the worst for this. Too many namespaces. Overly verbose syntax. I haven't had many projects that needed to be done in either of these languages, and for that I'm truly grateful.

But the one that takes the proverbial cake, in terms of being cumbersome, would be PHP. The function calls structures are wildly inconsistent, and in addition to semi-colons and curly brackets, it also requires a dollar sign preceding every variable name.

As far as syntax goes, the group of programming languages with visually similar styles - PHP, Java, JavaScript, C and its variants - is such that if you pick one up, the learning curve for the others, at least for the simple stuff, isn't so great. Thus, even if PHP is hideously cumbersome in parts, it benefits from being visually similar to other languages mentioned.

Transferable skills

This measures underlying principles or skills that one will pick up while programming in a certain language, that will be useful when transitioning to another stack. It could be something as simple as similar syntax (as mentioned earlier) or strong data typing.

Or it could be something so ubiquitous that no matter what stack you're in, you're almost certainly going to encounter it. A great example of this would be SQL. No matter what kind of programming you go into, the chances of you needing to access a database at some point, are pretty good. I wouldn't go so far as to say that this makes SQL the number one choice for a programmer's first language, but it makes a great case for being a programmer's second, at least.

Data processing.

For a similar reason, if one wanted to go into web development, it's almost impossible not to have to deal with HTML, CSS and JavaScript, but learning JavaScript as a first language just for that, is questionable. As a second language, definitely.

Strongly-typed, class-based languages such as Java and C# would be good choices as a first programming language for learning concepts such as Object-Oriented Programming. (PHP and JavaScript kind of implement OOP as well, but in a way that's a little odd). Python would be the choice if one wanted to have a strong foundation in data structures. However, Python's lack of strong typing might work against it as a first language.

Ease of setup

One of the most daunting tasks of learning a language is setting up the environment for it. Java requires the JRE (Java Runtime Environment). PHP requires an Apache server. Python and Ruby, well, you get the idea.

For this, the most fuss-free option has to be JavaScript, hands down.

All major browsers
run JavaScript.

JavaScript runs on all major browsers. You don't need to install anything you probably don't already have. If you're reading this, unless you're reading it on your phone, you have a desktop browser which you can run JavaScript in. It's almost zero setup. Just write your code, and run it in the browser.

For a Windows environment, VBScript is also almost zero effort. All you need to do is write your script, save it with extension "*.vbs" and you can run it by double-clicking it! Unfortunately, I'm not sure how useful knowing VBScript is.

In essence, in the cases of both JavaScript and VBScript, the environment has already been set up for the programmer.

Popular support

No developer plies their trade without consulting a reference of some sort. Textbooks are a valid source, but for the most updated material, we turn to the internet. Portals and forums provide most of these, with each language having large communities of programmers ready to provide support.

Learn by reading, or
by community.

Which programming language has the largest, or best, communities?

That's hard to say. All communities have their fair share of toxic losers who waste little time being condescending and acting like gatekeepers. At the same time, each community also boasts genuine people. I'm not going to waste time detailing how large each programming language's community is relative to others. Suffice to say, they're all (OK, mostly) large enough to be useful.

Generally, the longer they have been around, the larger they tend to be.

Conclusion

Whatever the choice turns out to be, ultimately, there will be benefits to that choice. That is because no matter what language someone chooses for their first programming experience, the fact remains is that they are still engaging in the activity of programming. It's a start. Some starts are better than others, sure, but it's a step. And hopefully the first of many.

Mind your (first) language!
T___T

Tuesday, 11 January 2022

Functional Terminology

Some terms in programming tend to confuse new programmers. There's a certain historical context to them, and with the rise of more recent technology, new terms muddy the waters a bit.

And among these terms are: function, subroutine and method. They all seem to be referring to the same thing - procedures - but there are some significant differences.

Today I will be attempting to provide some clarity.

Subprocedures

These are procedures that exist in a block of code, and can be called from anywhere. Arguments could be passed into them, optionally. In QBasic back in the day, there was a specific keyword for that.

SUB HELLOWORLD()
    PRINT "HELLO WORLD"
END SUB


CALL HELLOWORLD()


Basically, the subprocedure would perform whatever operations the programmer put in it, and that would be the end of it. This has all but vanished from the programming landscape. These days, it's all about functions, which we will examine below.

Functions

Functions are also procedures that exist in a block of code, and can be called from anywhere. Arguments could be passed into them, optionally. The difference is that after performing the operations, they return a value.

This is how it was done in QBasic or Visual Basic.

FUNCTION HELLOWOWLD(str)
    HELLOWORLD = str
END FUNCTION


PRINT HELLOWORLD("Hello world")


Or in JavaScript...
function helloWorld(str)
{
    return str;
}


console.log(helloWorld("Hello world"));


...and in certain cases may not even return anything.
function helloWorld(str)
{
    console.log(str);
}


helloWorld("Hello world");


So in these cases, a function works just like a subroutine, and thus subroutines are not really needed any more.

Methods

Now we come to methods. Methods are just like functions in every way... except for access control.

We call a function a method when it's part of an object. This is an example in JavaScript.
let obj =
{
    helloWorld: function (str)
    {
        console.log(str);
    }
}


So if we were to call this method, we can only call it when specifying the parent object.
obj.helloWorld("Hello world");


If we were to treat it like any other function, it would not work.
helloWorld("Hello world");


In some object-oriented programming languages such as Java or C++, if you specify that the class is Private (for instance), the method can only be called within the class itself. There's actually a fair bit to cover on this subject, but it's out of scope for this blogpost.

Finally()

As long as you have a clear idea of what you are referring to when you use these terms, end of the day it doesn't really matter what terms you use. Communication is key. Just don't be confused when the context changes, and the terms change with it. Ultimately, it's generally the same thing.

Play that func-y music!
T___T

Thursday, 3 October 2019

TeochewThunder: Year Five (Part 1/2)

This October marks the fifth year since TeochewThunder was started, and what a journey it has been so far. There's been plenty to write about, and I'm not running out of material anytime soon. Although there have been times I just didn't feel like writing. Blogging is an exercise in discipline. It forces me to keep exploring; keep my eyes, ears and mind open for more related topics, and most importantly, it keeps me honing my craft. It's a veritable ocean out there and I'm a shark; if I ever stop, that's it for me.

Can't stop!


Still, compared to hectic madness that was 2018, this year was a breeze. Being married and all, I can't devote as much time to this enterprise as I'm used to, but sometimes it's all about time management.

It also gives me a sense of purpose. Because work can drive me nuts... and when I get home, I need something to remind myself that I still love this shit. Something fun. Something productive.

Tutorials

2019 is the year I return to my roots - instantly browser-executable HTML, CSS and JavaScript, but with additional front-end niceties like jQuery UI, AngularJS and ReactJS thrown in. My style of coding has changed slightly. I'm now particular about spacing and indentation (fine, more particular than before) and when I do get the chance, my preferred style skews towards Object-oriented Programming. Happily, I still find time to do a little PHP, Ruby and QBasic.

Nothing really significant has changed otherwise; I'm still the nerd who codes outside of office hours and derives more pleasure than is reasonable from it. This results in at least one web tutorial a month, and I plan to maintain that standard.

Reviews

There have been a lot of reviews in TeochewThunder this year. Almost every month, there's been a review of some sort or other, and happily, they have been somewhat evenly spread out between film, app and fiction reviews. Reviews are easy to write, usually, and I've discovered a newfound enthusiasm for it. Also, many of these are backdated. While I collect the screenshots and all, I don't always have time to write all these reviews.

This blog is about more than tech reviews! And I have to be careful not to turn this into a review blog.

Miscellaneous Features

Spot The Bug. I manage about three of these a year, and to this day, I have not broken that streak.

Ropework analogies. One a year seems reasonable. Again, I've managed to keep that up, though this year's seemed a little trite. No matter, all part of the journey.

Listicles. These are fun to make; however they're also a lot of work. They used to be a good way to group related ideas into one blogpost so I wouldn't have to overlap too much when discussing similar ideas next time.

Work on teochewthunder dot com

Things have gotten a wee bit more expensive since 2018, what with me paying for hosting. Still, considering the benefits that this resource brings me, it's a small price to pay.

I get a domain name and a portfolio for prospective employers. It isn't great, but it's a heck of a lot better than nothing, which incidentally is what many developers have other than a resume and a lot of bravado. I don't really understand why other web devs don't invest in a domain name and hosting, especially when they're technically more skilled than I am and have a lot more to showcase. But it works in my favor and you know what they say about looking a gift horse in the mouth.

And it has worked. I attended interviews this year and the interviewers all mentioned the amount of code I've put online, along with my tech blogging. Sure, they don't always say it's good, but still. It's a body of work that has spanned years and it's being noticed by the audience for which it was intended.

All in all...

I sometimes struggle with not writing too much, especially when I have points that I want to make. But part of effective writing is restraint, and it's something that many people, not just me, could use more of.

Cutting away all that fat.


Every overly wordy Social Media post or article I come across annoys the living beejeezus out of me and I try very hard not to fall into that trap. These days, more time is spent trimming the fat than actually writing.

Next

Check out some of the stats on this blog!

Wednesday, 28 December 2016

The Quest For Mobile Knowledge (Part 1/2)

Back in 2013, I started experimenting with mobile development after obtaining my first smartphone. I borrowed a copy of Android Application Development for Dummies from the library, downloaded a working version of Android Studio, and got to coding.


I met with mixed results, and my progress was slow. Sure, my code worked, but only because I typed everything from the example faithfully. I had no idea why it was working. All I really gained from the experience was the knowledge that XML supplied the user interface markup and Java did the rest. Self-learning wasn't cutting it. I needed guidance; being told when I was doing it wrong, and when I was doing it right.

It was around this time in 2014 when I finally decided to get off my arse and work towards a third Diploma. I had just turned 37, settled in a new job, and the time seemed ripe. Before that, I had a Bachelor's Degree and Diploma in Information Technology, and a Specialist Diploma in E-commerce Technology. Diversify or die, that had been the mantra since I left the desktop support job back in 2008. One area that really stood out for me was mobile technology. Having been in web development for years now, I knew mobile technology was here to stay. And learning this stuff could only improve my web dev cred in terms of responsive design, front-end work and cross-platform compatibility. So I looked back to my two alma maters in Temasek Polytechnic and Singapore Polytechnic, but for pragmatic purposes, I chose to take up night classes in the latter as it was a stone's throw from my place.

Meet my classmates 

The first day was a little bit of a culture shock. I know that globalization and Singapore's liberal labor laws had increased the percentage of foreign labor, but still I was in for a little surprise when I realized that less than a quarter of the class were local professionals. Roughly half were from India. Burmese, Filipinos and Singaporeans made up the rest. Were my fellow citizens that set against self-improvement? Was that why I was hearing so many complaints about their jobs being taken away by "invaders"?

Even among the local professionals, there weren't many like me - a code monkey looking to expand his skill-set. They were mostly at managerial level trying to gain an understanding of mobile technology, probably so that they wouldn't get gypped by vendors. There were even a couple of network technicians. Now, I'm not disparaging network techs at all; in fact networking was one of the toughest subjects for me back in school and I have nothing but respect for those who are good enough at it to ply it as a trade. However, the fact remains that these guys not only had never done any kind of software development (much less web development), they had never written a single line of code in their careers. It leads me to think that they hadn't really thought this through and all they were doing was trying to cash in on the Government grants for professional development. And that whoever was vetting suitable applicants for the course, had either been snoozing that day, or taken a very liberal view as to what constituted "experience in web or software development".

All in all, my foreign classmates seemed more my kind of people. And so the first semester began...

Term 1

It all started out mostly with basic Java. Having my roots in C++, PHP and JavaScript made this a breeze. Having spent a year using almost exclusively C# back in 2012, sure didn't hurt. I got through the basics fairly quickly; in fact the real value of these lessons lay in using an IDE such as Eclipse for the first time. I gave myself a little test, implementing what I had done for this web tutorial, in Java. It was completed within minutes. I supplemented all this by reading Java SE 7 Programming Essentials by Michael Ernest. It's a good reference and I hope to review it sometime on this blog.


Concurrently, we were learning the theory behind mobile technology, what constituted web applications, native applications and hybrid applications. To further cement what I was learning, I blogged about it. This phase was more about drawing wireframes and mocking up mobile applications. I took special note of the tools used, such as Pencil. They would come in handy during my day job.

Term 2 

Now we were having fun in Java. We learned the basics of Object-oriented Programming in Java, and I began applying those concepts to my work in PHP and JavaScript as well. I'm not sure this actually improved the robustness of my work, but it definitely made it more extensible. And then we started making GUIs in Java, using the Swing library. This turned out to be interesting, and after handing in my project, I decided to embark on my own project - a memory game written in Java. To that end, I needed to use some stuff that wasn't covered by the lessons, such as timer functions for animations. Frequent reference to Oracle's documentation did the trick.



I'd be remiss here if I didn't give a little shout-out to my tenant Zhao from Guangdong, China. He'd been renting my guest bedroom for the past couple years. Sure, he had his little eccentricities that drove me nuts, such as this habit of singing cheesy pop songs in the middle of the night over and over, leaving the bathroom lights on the entire day… but he was also experienced in Java and a great help whenever I hit a wall. We had also begun learning JQuery Mobile, and this meant I was picking up jQuery as well. I practised what I could with jQuery, the results of which you can see in this web tutorial during Easter.


Again, to further drill in the process of creating a Single-page hybrid app in jQuery Mobile and porting it over to mobile using Cordova, I created a few apps in my own time - an expense tracker (which I’m still using to this day), a household chores tracker, and a mobile compass. During an annual medical checkup, my doctor gave me a valuable piece of advice: if I wanted to succeed at something, I had to make it part of my daily routine. In fact, I had to make it a part of me as much as possible. (She was actually referring to the task of lowering my cholesterol levels, but that’s another tale for another day.) That got me thinking. I wanted to manage my expenses better, right? And my household chores. And I wanted to learn how to make mobile apps.

The obvious solution? Make mobile apps to track my expenses and manage my household chores! I had learned all this really cool stuff, now I simply needed to apply it.

Next

A look at Semester 2

Wednesday, 2 March 2016

Spot The Bug: The Java Sentry

Good day, ladies and gentlemen. Spot The Bug is in town.

Time for some
bug-hunting!


This one is in Java. Not only that, it's a Java noob bug. Got a techie to look at it, and he couldn't figure it out either. Took an hour and boy, by the time I found it, it's so simple I could've died. I was trying to get a simple graphical interface for an Sign-in module up.

Here's what I was trying to accomplish. Simple enough? Well, apparently not!



What went wrong 

This happened.



The label and textbox simply did not show up. However, the window with title and all, opened just fine. Morever, there were no compiler errors. Here's the code for the classes.

Sentryguard.java
package tt_Sentryguard;
public class Sentryguard
{
    public static void main(String[] args)
    {
        SentryguardFrame frame=new SentryguardFrame();
        frame.setTitle("Guard on Duty");
        frame.setSize(800, 200);
        frame.setVisible(true);
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
     }
}

SentryguardFrame.java
package tt_Sentryguard;

import java.awt.Dimension;
import javax.swing.*;

public class SentryguardFrame extends JFrame
{
    private JPanel pnlSentryguard;
    private JTextField txtSentryguard;
  
    public void SentryguardFrame()
    {
        pnlSentryguard=new JPanel();
        txtSentryguard=new JTextField();
        txtSentryguard.setPreferredSize(new Dimension(300, 20));
       
        pnlSentryguard.add(new JLabel("HALT! Who goes there?"));
        pnlSentryguard.add(txtSentryguard);
       
        this.add(pnlSentryguard);
    }
}

I tried doing this instead - adding all the graphical interface elements from the main method instead of from the class. It worked! But that wasn't what I wanted. For a simple interface, it wouldn't matter. But if I had nested frames and an entire form of buttons, controls and what-have-you, this would get messy real quick. So no, I had to solve this problem rather than get around it.

Sentryguard.java
package tt_Sentryguard;

import java.awt.Dimension;
import javax.swing.*;

public class Sentryguard
{
    public static void main(String[] args)
    {
        SentryguardFrame frame=new SentryguardFrame();
        frame.setTitle("Guard on Duty");
        frame.setSize(800, 200);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(
        JFrame.EXIT_ON_CLOSE);
              
        JPanel pnlSentryguard=new JPanel();
        JTextField txtSentryguard=new JTextField();
        txtSentryguard.setPreferredSize(new Dimension(300, 20));
       
        pnlSentryguard.add(new JLabel("HALT! Who goes there?"));
        pnlSentryguard.add(txtSentryguard);
       
        frame.add(pnlSentryguard);
    }
}

So, back to square one. But that's OK, because it gave me a clue as to what was going on there. Obviously the code in Sentryguard.java was working fine, so the problem had to be in SentryguardFrame.java.

Why it went wrong 

The "void" in the SentryguardFrame() method was the problem. Because SentryguardFrame() is supposed to be a constructor. While public void SentryguardFrame() is technically legal, this meant that the program would treat SentryguardFrame() like any other method. The compiler would create its own default constructor in the absence of an programmer-specified one. But that default constructor would be blank, without any of the custom code I put in there. And SentryguardFrame frame=new SentryguardFrame(); would use that blank constructor instead.

How I fixed it 

Remove the "void" like so, and voila!
SentryguardFrame.java
package tt_Sentryguard;

public class SentryguardFrame extends JFrame
{
    private JPanel pnlSentryguard;
    private JTextField txtSentryguard;
  
    public SentryguardFrame()
    {
        pnlSentryguard=new JPanel();
        txtSentryguard=new JTextField();
        txtSentryguard.setPreferredSize(new Dimension(300, 20));
       
        pnlSentryguard.add(new JLabel("HALT! Who goes there?"));
        pnlSentryguard.add(txtSentryguard);
       
        this.add(pnlSentryguard);
    }
}

Moral of the story

It's often the innocuous little keywords that catch us off guard. (heh heh) But this helped hammer home the difference between a constructor and any other method in Object-oriented Programming.

Silly bug. Avoid at all costs!
T___T