Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@netikras well you technically can access a static attribute/method from all class internal methods, sure. But that's not because of the static keyword you can access ALL attributes and methods from class internal methods (and all public ones from outside of it as well). Static just makes a class member object independent, so you can access the same value from each object or without even creating an object. Same for calling a static method.
So the explanation doesn't necessarily make the code not work or anything, it's just wrong. Again, they were still learning procedural programming, so they didn't even create any objects, literally everything they did was static. -
@Ranchonyx static makes a member object independent, so you can access the same value (in case of static attribute) or call the same function (for static methods) from any created object or without creating an object at all.
Nothing to do with visibility or accessibility, right? ^^ -
@CodingPeasant i think the teacher's explanation of static is almost correct and probably the best worded to stick in the mind. its tru that any public functions can be accessed by object, or any internal functions can be accessed by children, but that static is simply a way to access a function/variable from any class (in the same module), irrespective of the hierarchy or other OO principles.
i might be partially wrong , bit i have been working with java/kotlin classes for last 6 years, and i would explain static exactly like this to someone at first -
@CodingPeasant now give this explanation to an intern and watch new side questions arising in their quiet, shy and overwhelmed faces and confusing them completely for another week. And if they'll overcome their shyness to ask a qn - soon you'll end up analyzing generational memory layouts and GCs' PLABs and TLABs.
Now carry on with your lecture. They'll learn jack and will start believing the stereotype that java is too complicated for them and in general.
It's a rabbit hole. Gotta be very careful what to say and when. If you know the internals, doesn't mean you have to blurp it all out whenever you get the chance -
@netikras I just wouldn't explain it at all at first. Just "you'll need this for now, it's gonna become clear why you do later on" and leave it at that. You wouldn't try to explain "public static void main" when showing someone how to do a hello world program. Maybe that's just differing styles, who knows, but my friend didn't get it when the teacher explained it and did get it when I explained what it actually did (with the preamble that it would make more sense later)
-
@dotenvironment interesting. I feel like the explanation and what static does have pretty much nothing in common, but that might be different ways of thinking. I actually didn't think anyone would disagree here, but good to know there's people who agree with the teacher xD
The biggest problem I see is that they didn't do anything non-static anyway, so for me there wasn't even the need to explain it at all, at least no more than "you'll need this for now", same as you'd skip explaining everything in "public static void main" for the first hello world program. But if you explain it, it should be correct (in my opinion ^^) -
@CodingPeasant looks like you are more concerned about how he explained in lesser depth than the actual definition of the term.
you should checkout : "an Instrument that record, analyse, summarise, organise, debate and explain information that are illustrative, non illustrative,hard bound paper bag jacketed, non jacketed, with forward introduction table of contents, index that are intended for the enlightenment, understanding, enrichment, enhancment and education of the human brain through sensory route of vision... some times touched" :P -
@dotenvironment nice one, maybe I should check that out, it sounds at the very least very precisely defined :P
But no, I honestly think the opposite, it was trying to explain more than it had to at that point in time, and for my friend it was confusing ^^ they didn't see the point of it until I explained it how I did in the previous comments ^^
quite an obvious result, but: seems like different people respond better to different teaching approaches xD -
I agree with @CodingPeasant that the teacher's definition is not correct...
a class member or method does not get MORE available / visible to class methods if the key word static is used.
to class methods it only makes a difference in terms of "is defined for a very object" or "is defined for the class itself, thus uniform for and irrespective of all objects of that class"
the teacher's description suggests static is some kind of access modifier within the class, whereas static really modifies variable lifetime and allocation, but these concepts remain unmentioned. -
TheEnd7032yI feel like the importance of how static works is one of the most poorly taught things in programming. Even seniors get static data wrong all the time. I’ve made a career out of refactoring PII info out of static members and being called a wizard for doing so. Instruction materials should include static data and static methods so that newcomers understand why and when to use these things…and when NOT to use them.
-
I think this is partly the reason why so many people hate Java, it's their first language and they are probably on old version of it trying to learn basics of programming.
I had the same problem, but with php - was forced to learn php 3 or 4 to pass a class and hated every second of it.
The best part is even then that version was considered outdated. -
@nemetepst yeah, you can't just start with the OOP principles immediately, but doing procedural stuff first is... Very boilerplate heavy
-
It IS wrong. In my opinion. The teacher said that a static member can be accessed from any function of the class (presumeably the same class). From my experience with C# and Java, that's not what static is for! Any function can already access any private member/public member of the same class!
A static member is a member of that class, that you can use from other code without the need of instantiating that class with the new keyword. -
@daniel-wu precisely my opinion. After the first two comments here were on the teachers side I really thought I was going mad xD
-
@Ranchonyx
static - is on the class itself, not the object that is the instance of the class. -
@Ranchonyx oh, didn't notice. i rarely check dates, i just assume that if it showed up towards the top of the feed, it's relatively new
Related Rants
Helped a friend who's currently learning programming in Java
Looked at the slides used to teach them and apparently the teacher explains the "static" keyword as "can be accessed from any function of the class"... Which... Isn't at all what static does
At that point they hadn't started with actual OOP stuff, so I kind of get why they didn't explain what it really does, but why the fuck did they just put down a completely wrong definition?! Instead of just saying "yeah you'll just need that keyword for now, I'll explain it later"
rant
java
static
teaching