Category: Uncategorized

Programming jargon crusher: functions,methods and complex objects.

Share

You’re with me so far?

I hope so!

Let’s talk about functions.

So, what’s a function in programming?

It’s just a piece of code that does a specific task
and return a specific value.

Easy, right?

Let me give you an example.

Let’s use a standard Javascript function called round
that will round it’s argument to the nearest integer number.

An argument is just a value that we pass into a function.

A function can have many arguments, in our case we have only one.

So, to use or run this function you need to write something like that in your code:

Math.round(1.2);

Let’s ignore for a moment the fact that there’s Math. before our function’s name. I will
explain that in the moment.

So, this function will return 1, right? This is the nearest integer for our first argument which is
1.2.

Here’s the thing:
when you actually put this function into your code like that, you won’t see a thing.

Why is that?

Well, we didn’t actually save a return value anywhere. Right?

And, what do we use to store values? Do you remember?

I’m sure you do:) A variable, right?

So, if you want to actually use a value or a result of this function you would have to write
something like that:
var myroundnumber = Math.round(1.2);

Then our newly created variable called myroundnumber will store a number 1 which is the result
of our round function.

When you look at our first web mapping application will see plenty of functions like that
and variables that store their results, in our code example map_app7.html we have:
In line 14:
var mymap = L.map(‘mapid’);

It looks quite similar, right?

We have a different function, in this case it’s called map (again we’re ignoring L. for now)
and instead of having a number as a first argument we now have a text.

And if you have a look at the rest of the code, you will see that we’re using function all the time
in that way.

Of course, we have different kinds and numbers of arguments,but basically it’s all the same.

Ok, let’s clarify this Math. and L. confusion. What’s that about?

So, those are objects. Our function belong,so to speak, to two different objects.

As you remember an object is a way to group values using keys. Like an index at the back of a book.
Right?

Math and L objects are more complex in a way that instead of storing values they store functions.

The only thing that you need to know is that a function that belongs to an object is called its method.

So, Math.round is really a function that belongs to a Math object.

What about L object?

As you probably remember from our second class in L object we have most of the Leaflet’s web mapping
library functionality.

So, what you’re mostly do when you’re building a web mapping application is you use L’s functions (methods)
to create a web map, center it etc.

Ok, let’s recap:
A function is just a container for a piece code.

When you run a function,it’s like you would run a code that is inside it.

A function can have arguments which are basically values that we can pass inside a function.

After function runs it will return a value. To save it you need to store it in a variable.

Functions that belongs to an object are called methods.

Objects can store simple keys and values (numbers or text) or functions.

Ok, that’s it for now:)

Let me know if you have any questions!

Share

The greatest gift you can receive

Share

We often value gifts that comes from someone else. We think that they’re most valuable.

We’re really happy if someone thinks about us and give us something special. If someone appreciate us that way we also feel appreciated and loved.

It’s interesting that we expect to be appreciated,but we rarely do it to ourselves. We want to be respected,but often fail to expect our unique personalities. We want to be valued,but forget to find a value in what we do and how we do it.

But there are things that only you can give yourself, no one else.

If you’re busy looking for a new job, every break seems like a waste of time. You’re in the rush, there’s plenty to do, one more job site to look at, one more post to read, one more resume to send.

But the reality is that been busy does not equal getting great results. It’s awesome that you’re in motion. But when you’re stressed out or burned out doing more will only make things worse.

I found that when my mind is fresh and rested I come up with good ideas. And when there’s problem it’s easier for me to find the right solution.

Sometimes we’re running so fast it’s difficult to slow down. Even on Christmas. You might not doing anything, but you’re still thinking about your job and things that needs to be done. It’s counterproductive because you’re not really having any break. And you’re not really effectively working on anything else either. But your mind is still active.

Over the years I found a couple of ways to refresh my mind. And there’s one that always works for me.

I found that I need to engage my whole body to actually refresh my mind. I’m then focused so much on what I do that I can’t think about anything else.

I love winter and I love winter sports. I used to ski a lot, but for a few years now I’m fascinated by snowboarding. It’s a great way to clean up my mind. I love it.

It’s easy to tell myself that I can do just fine without taking a longer break. That’s been busy all the time will bring better results.

But when I let myself enjoy a day in a snow I found that a lot of things gets easier. I felt reconnected to what I’m doing. Fresh ideas flows easily into my mind. I’m more productive. And in the end I do more. Not less. And I’m enjoying what I’m doing more.

The greatest gift that you can receive is the one that you can only give yourself. It’s permission to give yourself a break. No one can do it for you. Only you.

It’s not only about taking break from action. It’s also taking a break from thinking. And Christmas is a great time to do just that.

Find something that you can engage yourself in so deeply it that will let you relax completely for a while.
Then you will discover that it’s really a fundamental part of finding a great job.

Share