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
-
So after refilling your coffee you just leave It there, not drinking it?
That's an barbaric act. -
Also: every time the code gets executed, the coffee instance gets recreated and if there is no random mechanism choosing whether or not the coffee is filled in the constructor, it will always be refilled and never get consumed 😂
-
Kimmax111067y@itsdaniel0 depends. If it's C# it should be as a Property, like above. I know the Java guys like to wrap it in functions,so your case might be true too
-
JohanO20507yA property _is_ a function - never forget that!
Its so easy to think that .Empty would be "cheaper" than .IsEmpty() - its just kinda like a "field" right? Well, you dont know what code lies behind that simple property, it could be a thousand lines... -
zfor14867yThe whole thing should be wrapped in a while(true) loop. At the moment you just wasting your coffee.
-
7Raiden8787y@JohanO As far as I know getter and setter in C# are managed by creating an additional variable that begins with an underscore and then the name of your property.
The code that goes behind it's what you write in the getter/setter.
So, yeah, it might be 1k LoC, but it might as well be 1! -
@7Raiden I'm not sure there's a cache involved. If you made something equal DateTime.Now, it would return the date and time when it was called. Effectively calling the function each time
-
@JohanO
Uhm.. it could only be a thousand lines if it were a function. If I select a field then I am guaranteed to only access this field.
Or am I wrong here? -
@stimulate I'm not sure about other languages, but in .NET a getter (and setter for that matter) could certainly be 1000 lines. It could even call on an API service somewhere
-
@itsdaniel0
That is what I am saying. A function could contain anything. A field is guaranteed to be a variable of type x. -
@stimulate It would still be accessed as a field though...
E.G.
public class User {
public string Username
{
get {
var result = api.getUsername(userId);
return result;
}
}
}
That would be accessed as a field like so...
var usr = new User();
usr.Username; -
@itsdaniel0
Ok that's pretty different to C, which is what I am used to. This seems to encapsulate a function call into the access of a variable.
In that case, of course it is hard to tell what actually happens when "api.getUsername(userID);" is called to get the string variable Username.
Related Rants
!rant
My girlfriend just got those for her laptop
undefined
mac
coffee
stickers