Do You Have (Or Have You Seen) Twitches in Programming ?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Do You Have (Or Have You Seen) Twitches in Programming ?

Post by Roland_Yonaba »

Well, I really don't know where this thread is going to go, but i'm leaving it up to you, folks.
Okay, as you might already know, I like looking at other's people source. Obviously, for learning purposes.
But at the same time, i sometimes notice some fun/strange coding habits. Or design patterns that results in a very clean code.

Note: Please keep in mind one thing. This is not for bashing anyone. But sharing useful tips, or gently teasing some folks. :megagrin:

I'll start with Leafo. Seen in ExoSlime source.

So, Leafo has the strange habit of adding _0 to each of his variables...
Well, maybe he can explain. :ultrahappy:

Code: Select all

 mixin_object = function(self, object, methods)
    local _list_0 = methods
    for _index_0 = 1, #_list_0 do
      local name = _list_0[_index_0]
....

    if keys then
      local _list_0 = keys
      for _index_0 = 1, #_list_0 do
        local key = _list_0[_index_0]
....

  _base_0.__index = _base_0
  if _parent_0 then
    setmetatable(_base_0, _parent_0.__base)
  end

...
{
    __index = function(cls, name)
      local val = rawget(_base_0, name)
      if val == nil and _parent_0 then
        return _parent_0[name]
      else
        return val
      end
    end,
    __call = function(cls, ...)
      local _self_0 = setmetatable({}, _base_0)
      cls.__init(_self_0, ...)
      return _self_0
    end
  }

....
    __call = function(cls, ...)
      local _self_0 = setmetatable({}, _base_0)
      cls.__init(_self_0, ...)
      return _self_0
    end
  })
  _base_0.__class = _class_0
  return _class_0
Okay, don't try to run them, these are just random portions of his code.
Well share you own, or things you've seen, no matter what the programming language is or the framework/engine is.
Though Lua/love2D are preferred.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Do You Have (Or Have You Seen) Twitches in Programming ?

Post by coffee »

Roland_Yonaba wrote:Well, I really don't know where this thread is going to go, but i'm leaving it up to you, folks.
Okay, as you might already know, I like looking at other's people source. Obviously, for learning purposes.
But at the same time, i sometimes notice some fun/strange coding habits. Or design patterns that results in a very clean code.

Note: Please keep in mind one thing. This is not for bashing anyone. But sharing useful tips, or gently teasing some folks. :megagrin:

I'll start with Leafo. Seen in ExoSlime source.

So, Leafo has the strange habit of adding _0 to each of his variables...
Well, maybe he can explain. :ultrahappy:

Okay, don't try to run them, these are just random portions of his code.
Well share you own, or things you've seen, no matter what the programming language is or the framework/engine is.
Though Lua/love2D are preferred.
I totally confess that I do and want have that kind of twitches (not using _x it self). And I don't call it that. It's more a proper way of self-organization. Leafo is actually coding brilliant for his script stuff but I personally really don't like the way how he "complicate" Lua. Nothing against the twitches if that is compreensible by them (and others).

I personally like to have different ways of begin and end variables with something unique according his "type" (arguments, vars used in cycles, normal vars and so on). One good thing on this is less changes of bad replacements in find/replace.

I could be wrong but the _0 _1 and so on could mean the deepness of the variable in the table tree.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Do You Have (Or Have You Seen) Twitches in Programming ?

Post by kikito »

Prefixing the same text to all/most variables/functions is called Smurf Naming Convention - It's item 21 on this list (by the way, go check it up for general "twitches"). I don't think there is a name for "adding the same suffix" though.

My favorite one is "yoda conditions", i.e. typing this:

Code: Select all

if 5 == count then
instead of this:

Code: Select all

if count == 5 then
The justification being that if you type "=" instead of "==", the program will error on the first case, and not on the second (so you will have a hidden bug).
But Lua will give you an error in both cases, so it doesn't make sense to carry those "practices" from other languages which allow assignations inside conditions. (I don't think they are a good practice even in those, but that's another story...)
When I write def I mean function.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Do You Have (Or Have You Seen) Twitches in Programming ?

Post by Roland_Yonaba »

kikito wrote:It's item 21 on this list (by the way, go check it up for general "twitches")
That's a very edifying article. Being a fan of Pokemon, I just loved the :
For when you just Gotta Catch 'Em All.

Code: Select all

try {
}
catch (Exception ex) {
   // Gotcha!
}
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Do You Have (Or Have You Seen) Twitches in Programming ?

Post by Xgoff »

coffee wrote:
Roland_Yonaba wrote:Well, I really don't know where this thread is going to go, but i'm leaving it up to you, folks.
Okay, as you might already know, I like looking at other's people source. Obviously, for learning purposes.
But at the same time, i sometimes notice some fun/strange coding habits. Or design patterns that results in a very clean code.

Note: Please keep in mind one thing. This is not for bashing anyone. But sharing useful tips, or gently teasing some folks. :megagrin:

I'll start with Leafo. Seen in ExoSlime source.

So, Leafo has the strange habit of adding _0 to each of his variables...
Well, maybe he can explain. :ultrahappy:

Okay, don't try to run them, these are just random portions of his code.
Well share you own, or things you've seen, no matter what the programming language is or the framework/engine is.
Though Lua/love2D are preferred.
I totally confess that I do and want have that kind of twitches (not using _x it self). And I don't call it that. It's more a proper way of self-organization. Leafo is actually coding brilliant for his script stuff but I personally really don't like the way how he "complicate" Lua. Nothing against the twitches if that is compreensible by them (and others).

I personally like to have different ways of begin and end variables with something unique according his "type" (arguments, vars used in cycles, normal vars and so on). One good thing on this is less changes of bad replacements in find/replace.

I could be wrong but the _0 _1 and so on could mean the deepness of the variable in the table tree.
knowing leafo, that's probably lua code generated from moonscript
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Do You Have (Or Have You Seen) Twitches in Programming ?

Post by bartbes »

Xgoff wrote: knowing leafo, that's probably lua code generated from moonscript
I am actually 100% sure it is.
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Do You Have (Or Have You Seen) Twitches in Programming ?

Post by Inny »

Yeah, the _0 behavior is a Moonscript thing when generating code for the class and extends keywords. Speaking of which, look at the monstrosity that moonscript generated with inheritance: http://moonscript.org/reference/#inheritance
User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Do You Have (Or Have You Seen) Twitches in Programming ?

Post by qaisjp »

People who don't indent or don't use CamelCase don't deserve to know how to script.

Code: Select all

function HELLOWORLD()
print(   "h")
print (      "e"      )
print(        "l")
print(         "l")
print"           o"
end
virtually useless coders..
Lua is not an acronym.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Do You Have (Or Have You Seen) Twitches in Programming ?

Post by BlackBulletIV »

kikito wrote:My favorite one is "yoda conditions", i.e. typing this:

Code: Select all

if 5 == count then
instead of this:

Code: Select all

if count == 5 then
The justification being that if you type "=" instead of "==", the program will error on the first case, and not on the second (so you will have a hidden bug).
But Lua will give you an error in both cases, so it doesn't make sense to carry those "practices" from other languages which allow assignations inside conditions. (I don't think they are a good practice even in those, but that's another story...)
Besides that, I think any programmer who knows what they're doing will only make that mistake rarely (and never by confusing the operators).
qaisjp wrote:People who don't indent or don't use CamelCase don't deserve to know how to script.

Code: Select all

function HELLOWORLD()
print(   "h")
print (      "e"      )
print(        "l")
print(         "l")
print"           o"
end
virtually useless coders..
Everyone has their style, and there are a number of worthy naming schemes out there other than camel case, such the underscore case (foo_and_bar), though I personally prefer camel case. But you're right about indentation; it's inexcusable not to use it.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Do You Have (Or Have You Seen) Twitches in Programming ?

Post by coffee »

BlackBulletIV wrote:Everyone has their style, and there are a number of worthy naming schemes out there other than camel case, such the underscore case (foo_and_bar), though I personally prefer camel case. But you're right about indentation; it's inexcusable not to use it.
That's why the discussions "this is the way to code", "you should code in that manner", "my style is better than yours", ends to be worthless when eventually turns to be hidden ego "I'm better coder than you" discussions. What seems important to me is be CONSISTENT and to always obey to that practices adopted either himself or by the team. Twitches in styles are always valid if work, are functional, reduce coding time and bring clear organization to project. However if the project is to open-sourced, outsourced, key-in-hand or be transferred common naming practices should be otherwise used instead of self-namings.
Post Reply

Who is online

Users browsing this forum: No registered users and 224 guests