stupidly long variable name!

BlitzMax Forums/BlitzMax Programming/stupidly long variable name!

skn3(Posted 2007) [#1]
I just created the longest variable name I have ever used

window_client_tabber_network_controls_toolbar_refresh_itemid:Int = 0

Enjoy!


GfK(Posted 2007) [#2]
Thats just silly.

I'm sure you could get this shorter if you wanted to.


CS_TBL(Posted 2007) [#3]
Is it a global? Considering the naming there seems to be some hiarchy like having types. I can't imagine that variables inside types grow this large.


fredborg(Posted 2007) [#4]
You could beat your own record by using:
window_client_tabber_network_controls_toolbar_refresh_item_identifier:Int = 0


Yan(Posted 2007) [#5]
Or...

window_client_tabber_network_controls_toolbar_refresh_item_identifier_wibble:Int = 0


CS_TBL(Posted 2007) [#6]
or increase the amount of underscores ..


skn3(Posted 2007) [#7]
Haha it is from
'### gui ###
Const _imageroot:String = "images/"
Const _imageformat:String = ".png"

Global window:tgadget = CreateWindow("Master admin",10,10,500,500,Null,WINDOW_TITLEBAR)
	Global window_status:tgadget = CreatePanel(0,ClientHeight(window)-20,ClientWidth(window),20,window)',PANEL_BORDER)
	
	Global window_client:tgadget = CreatePanel(0,0,ClientWidth(window),ClientHeight(window)-GadgetHeight(window_status),window)
		Global window_client_tabber:tgadget = CreateTabber(0,0,ClientWidth(window_client),ClientHeight(window_client),window_client)
			'network tab
			Const window_client_tabber_network_itemid:Int = 0
			AddGadgetItem(window_client_tabber,"Network",GADGETITEM_NORMAL,-1,"Browse the network")
			Global window_client_tabber_network:tgadget = CreatePanel(0,0,ClientWidth(window_client_tabber),ClientHeight(window_client_tabber),window_client_tabber)
				HideGadget(window_client_tabber_network)
				'network controls
				Global window_client_tabber_network_controls:tgadget = CreatePanel(0,-2,ClientWidth(window_client_tabber_network),24,window_client_tabber_network)
					Global window_client_tabber_network_controls_toolbar:tgadget = CreateToolBar(_imageroot+"network_controls"+_imageformat,0,0,ClientWidth(window_client_tabber_network_controls),ClientHeight(window_client_tabber_network_controls),window_client_tabber_network_controls)
						SetToolBarTips(window_client_tabber_network_controls_toolbar,["Refresh the network structure"])
						'network control toolbar buttons
						Const window_client_tabber_network_controls_toolbar_refresh_itemid:Int = 0
				
				'networks treeview
				Global window_client_tabber_network_treeview:tgadget = CreateTreeView(0,GadgetHeight(window_client_tabber_network_controls),ClientWidth(window_client_tabber_network),ClientHeight(window_client_tabber_network)-GadgetHeight(window_client_tabber_network_controls),window_client_tabber_network)
					Global window_client_tabber_network_treeview_icons:ticonstrip = LoadIconStrip(_imageroot+"network_treeview"+_imageformat)
						SetGadgetIconStrip(window_client_tabber_network_treeview,window_client_tabber_network_treeview_icons)
						
					Global window_client_tabber_network_treeview_root:tgadget = TreeViewRoot(window_client_tabber_network_treeview)
						Global window_client_tabber_network_treeview_root_master:tgadget = AddTreeViewNode("master",window_client_tabber_network_treeview_root,0)
			
			'logs tab
			Const window_client_tabber_logs_itemid:Int = 1
			AddGadgetItem(window_client_tabber,"Logs",GADGETITEM_NORMAL,-1,"View logs")
			Global window_client_tabber_logs:tgadget = CreatePanel(0,0,ClientWidth(window_client_tabber),ClientHeight(window_client_tabber),window_client_tabber)
				HideGadget(window_client_tabber_logs)



Warren(Posted 2007) [#8]
That is terrible. Completely unreadable.


fredborg(Posted 2007) [#9]
Oh my!


CS_TBL(Posted 2007) [#10]
For XXX's sake!

That's why bmax has .., to split these long commands into pieces.
Global window_client_tabber_network_treeview:tgadget =..
CreateTreeView(..
0,..
GadgetHeight(window_client_tabber_network_controls),..
ClientWidth(window_client_tabber_network),..
ClientHeight(window_client_tabber_network)-GadgetHeight(window_client_tabber_network_controls),..
window_client_tabber_network)

Globals are evil anyway.. sooner or later you'll want to merge your stuff into some other enviroment and you'll never know whether a similar variable was defined there already.


CS_TBL(Posted 2007) [#11]
oh, and if you aren't using the variables CW, CH, GW and GH, then make alternative functions for ClientWidth, ClientHeight, GadgetWidth and GadgetHeight .. :P


Azathoth(Posted 2007) [#12]
What about win instead of window, and ctrls instead of controls?


Gabriel(Posted 2007) [#13]
Forget the variable name. Why the seemingly random use of indentation?


Tom Darby(Posted 2007) [#14]
I'm a big fan of longer, descriptive variable names, but this is just insane...


JoshK(Posted 2007) [#15]
Here's one of mine:
COLLISIONOBJECT_GADGET_JOINT_COLLISIONOBJECT0_LISTBOX


Perturbatio(Posted 2007) [#16]
Forget the variable name. Why the seemingly random use of indentation?

At a guess, the indentation is showing the hierarchy of the objects.

It's something I do myself, but I do steer clear of variable names that long wherever human(e)ly possible. :)


skn3(Posted 2007) [#17]
peturbatio is correct. It is for the object hierachy!

I agree the names are a little insane but i dispise truncated names like ctrl win bigsoplk78mnoplik_1. It will pay off later when there are a TON of gadgets. The application it belongs too is going to have probably 10 or more seperate tabs, each a unique application in its own right.

Last time I made a big scale application like this I ended up frustrating myself round the twist having to always look-up the handle names. This time it is just a matter of remembering the path of items.

On a side note, this is the first post using my new macbook.. Mmmmm white!


Beaker(Posted 2007) [#18]
Is it just me or are you missing the point of object orientation? Particularly if you have an IDE that has code completion for objects?

Maybe I've been using other languages too much recently.

A crappy example:
SuperStrict
Type network
	Field blah:Int
End Type

Type tabber
	Field net:network = New network
End Type

Type window_client
	Field tab:tabber = New tabber	
End Type

Local win:window_client = New window_client
win.tab.net.blah = 50


At least then someone else can see the structure of your data/variables, as it is declared up front.


xlsior(Posted 2007) [#19]
On a side note, this is the first post using my new macbook.. Mmmmm white!


Hope you like yellow too? http://news.com.com/2061-10793_3-6083486.html


plash(Posted 2007) [#20]
Mmmm... light yellow?


Was this thread completely just to see if the mac worked on the internet?


Picklesworth(Posted 2007) [#21]
Hah, beat this!
	Function DefineKey()
	Rem
	After a lot of fidgetting (and a regrettable dropping of a great
	bit of automagic code), the plan here is currently as follows:
	Any code can define these Keys, which are used to identify chunks of
	data for Extensions. For example, the model loader base could define
	a Key for MODELLOADER_FileType. Any Extension could then apply a 
	value to that key in their ExtensionData.
	
	At the moment, an extension function depending on a container which
	does not exist will simply not work. I am hoping that it will eventually
	be possible to actually disable such extensions automatically with
	the help of a precompiler...
	
	This definition of keys could be entirely done in a precompiler, and I
	am hoping to get it that way some day.
	
	Syntax to call this function is very primitive:
	Global MyKey=TExtensionData.DefineKey()
	Note that if other bits of programs are to have access to your key 
	(which they should), then you need to define it as a Global.
	It works, and no it is not remotely cool :(
	The idea here is abstraction at its simplest, I guess. Some day, if these
	things get more advanced, it won't be a problem to toss some more stuff
	into this little Keys "system".
	End Rem
		KeysCount=KeysCount+1 'Heh, kind of anticlimactic?
		Return KeysCount
	End Function

Thankfully, that code is now removed.


skn3(Posted 2007) [#22]
lol kinda sorta yes. I was suprised that the mac did indeed work on the tinternet! they have come along way since i used one ;)


Curtastic(Posted 2007) [#23]
haha I acutally like your naming system.

My longest is a function. from my RTS.
WorkerResourceGatherTileFindStart()
Which translates to "Have the worker begin to search for a tile to gather a resource from."


Picklesworth(Posted 2007) [#24]
I have now been reminded why OOP is a good thing...


Jake L.(Posted 2007) [#25]
I once was in bad mood while coding at work, so I named a local loop variable "fu**ing_dumb_loop_var". The app went beta and was given out to our customer.
Two weeks later I got a call from our customer reporting an error, He said, sometimes a messagebox appears telling him that f**ing_dumb_loop_var raised a DivisionByZero in Line xyz.

Not easy to explain this to a customer while the whole office-crew laughed their asses off.

So, be careful how you name things ;)


TomToad(Posted 2007) [#26]
Jake, you wouldn't be the one that wrote the Pub.mod/libjpeg.mod module would you? :D
http://www.blitzbasic.com/Community/posts.php?topic=59127


skn3(Posted 2007) [#27]
beaker,

But whats the point in making a new object just to store one thing ? OOP is a bit pointless if your just going to have one instance of it that doesnt actualy require any of the features of OOP. The naming convention is just for memories sake. Im sure I could write a one size fits all object but that would be messy.

I could probably truncate the window_client_tabber_network bit off and change it too tab_network_. But what if that tab didnt belong to window, what if it belongd to popup1 ?.

Jake, funny story. Yes just last week i put an annoyed curse into a php comment. Lol!


Beaker(Posted 2007) [#28]
Because its clearer, self-contained and more re-usable. In this case OOP is definitely not pointless.

Just because there is only one object doesn't remove the benefits of OOP. Its common practise to only create one object.

You said yourself that each tab is going to hold an application in its own right. So, why not make each application an object?


skn3(Posted 2007) [#29]
You make a good point. I will hav ea ponder at work tommorow :)


skn3(Posted 2007) [#30]
As suggested I have objectified it.

this is the new creation code
Global gmain:_gmain = _gmain.create()
Type _gmain
	Field window:gwindow
	Field tabber:gtabber
	
	Const networktoolbar:Int = 0
	
	Function hookupdate_networktab:Int()
		'this function is hooked by the update function
		Select EventSource()
			Case gmain.i.tabber
				Select EventID()
					Case EVENT_ACTION
						gmain.tabber.changetab(EventData())
				End Select
			Case gmain.tabber.tabs[0].gadgets[0]
				'toolbar event
				Select EventID()
					Case EVENT_ACTION
						'user has requested network information
						'disable refresh button
						gmain.tabber.tabs[0].gadgets[0].disablebutton(0)
						
						'clear the tree nodes
						tnetworktree.instance.clear()
						
						'request list of servers from the master
						tcpc_master.sendcommand(_command_adminrequestservers)
				End Select
			Case gmain.i.tabber.tabs[0].gadgets[1]
				'tree view event
				Select EventID()
					Case EVENT_ACTION
						'check if server / peer info window
						Local temp_peer:tnetworktree_peer = tnetworktree.instance.findpeerfromgadget(tgadget(EventExtra()))
						If temp_peer
							CreatePeerWindow(nip,nport)
						End If
				End Select
		End Select
	End Function
	
	Function create:_gmain()
		Local window:_gmain = New _gmain
		window.window = gwindow.create("Master admin",[10,10,500,500])
		window.tabber = gtabber.create(window.insiderect(),window)
		'network tab
		window.tabber.addtab("Network","Browse the network")
		window.tabber.tabs[0].addgadget(gtoolbar.create([0,0,window.tabber.tabs[0].insidewidth(),24],window.tabber.tabs[0],imagepath_networktoolbar,"Refresh the network"))
		window.tabber.tabs[0].addgadget(gtreeview.create([0,window.tabber.tabs[0].gadgets[0].outerheight(),window.tabber.tabs[0].innerwidth,window.tabber.tabs[0].innerheight()-window.tabber.tabs[0].gadgets[0].outerheight()],window.tabber.tabs[0],iconstrip_networktreeview))
		window.tabber.tabs[0].gadget[1].addnode("master",0)
		'window.tabber.tabs[0].setupdatehook(
		'log tab
		window.tabber.addtab("Logs","View traffic logs")
		window.tabber.tabs[1].addgadget(gtextarea.create(window.tabber.tabs[0].innerrect(),window.tabber.tabs[1],True))
		Return window
	End Function
End Type


this is the code that does the work
Import BRL.Win32MaxGUI
Import BRL.EventQueue

Type ggadget Abstract
	Global list:TList = CreateList()
	Field gadgets:ggadget[]
	Field gadget:tgadget

	Field _hookupdate:Int()

	Method update:Int()
		'this function should return true if it wants to halt gui updates
		If _hookupdate <> Null Return _hookupdate()
		
		'scan through all gadgets until a return was matched
		If gadgets.length > 0
			Local temp_i:Int
			For temp_i = 0 Until gadgets.length
				If gadgets[temp_i].update() Return True
			Next
		End If
	End Method
	
	Method setupdatehook:Int(nhook:Int())
		_hookupdate = nhook
	End Method
	
	Method show:Int()
		ShowGadget(Gadget)
	End Method
	
	Method hide:Int()
		HideGadget(gadget)
	End Method
	
	Method enable:Int()
		EnableGadget(gadget)
	End Method
	
	Method disable:Int()
		DisableGadget(gadget)
	End Method

	Method insidex:Int()
		Return 0
	End Method
	
	Method insidey:Int()
		Return 0
	End Method
	
	Method insidewidth:Int()
		Return ClientWidth(gadget)
	End Method
	
	Method insideheight:Int()
		Return ClientHeight(gadget)
	End Method
	
	Method outsidex:Int()
		Return GadgetX(gadget)
	End Method
	
	Method outsidey:Int()
		Return GadgetY(gadget)
	End Method
	
	Method outsidewidth:Int()
		Return GadgetWidth(gadget)
	End Method
	
	Method outsideheight:Int()
		Return GadgetHeight(gadget)
	End Method
	
	Method insiderect:Int[](noffsetx:Int=0,noffsety:Int=0,noffsetw:Int=0,noffseth:Int=0)
		Return [0+noffsetx,0+noffsety,ClientWidth(gadget)+noffsetw,ClientHeight(gadget)+noffseth]
	End Method
	
	Method outsiderect:Int[](noffsetx:Int=0,noffsety:Int=0,noffsetw:Int=0,noffseth:Int=0)
		Return [GadgetX(gadget)+noffsetx,GadgetY(gadget)+noffsety,ClientWidth(gadget)+noffsetw,ClientHeight(gadget)+noffseth]
	End Method
	
	Method addgadget:Int(ngadget:ggadget)
		Local temp_slot:Int = gadgets.length
		gadgets = gadgets[..temp_slot+1]
		gadgets[temp_slot] = ngadget
		Return temp_slot
	End Method
End Type

Type gwindow Extends ggadget
	Field window:tgadget

	Function create:gwindow(ntitle:String,nrect:Int[],nparent:ggadget=Null,nstyle:Int=WINDOW_TITLEBAR)
		Local window:gwindow = New gwindow
		Local temp_parent:tgadget = Null
		If nparent <> Null temp_parent = nparent.gadget
		window.window = CreateWindow(ntitle,nrect[0],nrect[1],nrect[2],nrect[3],temp_gadget,nstyle)
		window.gadget = CreatePanel(nrect[0],nrect[1],nrect[2],nrect[3],window.window)
		SetGadgetLayout(window.gadget,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED)
		Return window
	End Function
End Type

Type gtoolwindow Extends ggadget
	Field window:tgadget

	Function create:gtoolwindow(ntitle:String,nrect:Int[],nparent:ggadget=Null,nstyle:Int=WINDOW_TITLEBAR)
		Local window:gtoolwindow = New gtoolwindow
		Local temp_parent:tgadget = Null
		If nparent <> Null temp_parent = nparent.gadget
		window.window = CreateWindow(ntitle,nrect[0],nrect[1],nrect[2],nrect[3],temp_gadget,nstyle | WINDOW_TOOL)
		window.gadget = CreatePanel(nrect[0],nrect[1],nrect[2],nrect[3],window.window)
		SetGadgetLayout(window.gadget,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED)
		Return window
	End Function
End Type

Type gtabber Extends ggadget
	Field selected:Int = -1
	Field icons:ticonstrip
	Field tabs:gtab[]

	Method addtab:gtab(ntitle:String,ntip:String="",nicon:Int=-1)
		'create a new tab ggadget
		Local tab:gtab = New gtab
		'setup the tab
		tab.slot = tabs.length
		tab.gadget = CreatePanel(0,0,ClientWidth(gadget),ClientHeight(gadget),gadget)
		SetGadgetLayout(tab.gadget,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED)
		'resize tabs array for this new tab
		tabs = tabs[..tab.slot+1]
		tabs[tab.slot] = tab
		'add tab to tabber
		AddGadgetItem(gadget,ntitle,0,nicon,ntip)
		'hide the tab unless it is only current active tab in tabber
		If tabs.length > 1 
			tab.hide()
		Else
			selected = 0
		End If
		Return tab
	End Method
	
	Method changetab:Int(ntab:Int)
		If ntab > tabs.length Or ntab = selected Return False
		Local temp_i:Int
		tabs[selected].hide()
		tabs[ntab].show()
	End Method

	Function create:gtabber(nrect[],nparent:ggadget=Null,nicons:Object=Null)
		Local tabber:gtabber = New gtabber
		Local temp_parent:tgadget = Null
		If nparent <> Null temp_parent = nparent.gadget
		tabber.gadget = CreateTabber(nrect[0],nrect[1],nrect[2],nrect[3],temp_parent,nstyle)
		Local iconstrip:ticonstrip = ticonstrip(nicons)
		If iconstrip = Null
			tabber.icons = LoadIconStrip(String(nicons))
		Else
			tabber.icons = ticonstrip(nicons)
		End If
		If tabber.icons SetGadgetIconStrip(tabber.gadget,tabber.icons)
		SetGadgetLayout(tabber.gadget,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED)
		Return tabber
	End Function
End Type

Type gtab Extends ggadget
	Field slot:Int
End Type

Type glistbox Extends ggadget
	Field icons:ticonstrip
	
	Function create:glistbox(nrect[],nparent:ggadget=Null,nicons:Object=Null)
		Local listbox:glistbox = New glistbox
		Local temp_parent:tgadget = Null
		If nparent <> Null temp_parent = nparent.gadget
		Local iconstrip:ticonstrip = ticonstrip(nicons)
		If iconstrip = Null
			listbox.icons = LoadIconStrip(String(nicons))
		Else
			listbox.icons = ticonstrip(nicons)
		End If
		listbox.gadget = CreateListBox(nrect[0],nrect[1],nrect[2],nrect[3],temp_parent)
		If listbox.icons SetGadgetIconStrip(listbox.gadget,listbox.icons)
		Return listbox
	End Function
End Type

Type gtoolbar Extends ggadget
	Field toolbar:tgadget
	
	Function enablebutton:Int(nbutton:Int)
		EnableGadgetItem(toolbar,nbutton)
	End Function
	
	Function disablebutton:Int(nbutton:Int)
		DisableGadgetItem(toolbar,nbutton)
	End Function
	
	Function create:gtoolbar(nrect[],nparent:ggadget=Null,nicons:String="",ntips:String[]=Null)
		Local toolbar:gtoolbar = New gtoolbar
		Local temp_parent:tgadget = Null
		If nparent <> Null temp_parent = nparent.gadget
		toolbar.gadget = CreatePanel(nrect[0],nrect[1],nrect[2],nrect[3],nparent.gadget)
		SetGadgetLayout(toolbar.toolbar,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED)
		If ntips SetToolBarTips(toolbar.toolbar,ntips)
		Return toolbar
	End Function
End Type

Type gtreeview Extends ggadget
	Field icons:ticonstrip
	Field nodes:gtreeviewnode[]
	
	Method addnode:Int(ntitle:String,nicon:Int=-1)
		Local node:gtreeviewnode = New gtreeviewnode
		node.parent = TreeViewRoot(gadget)
		node.gadget = AddTreeViewNode(ntitle,node.parent,nicon)
		Local temp_slot:Int = nodes.length
		nodes = nodes[..temp_slot+1]
		nodes[temp_slot] = node
		Return temp_slot
	End Method
	
	Function create:gtreeview(nrect[],nparent:ggadget=Null,nicons:Object=Null)
		Local treeview:gtreeview = New gtreeview
		Local temp_parent:tgadget = Null
		If nparent <> Null temp_parent = nparent.gadget
		treeview.gadget = CreateTreeView(nrect[0],nrect[1],nrect[2],nrect[3],temp_parent)
		Local iconstrip:ticonstrip = ticonstrip(nicons)
		If iconstrip = Null
			treeview.icons = LoadIconStrip(String(nicons))
		Else
			treeview.icons = ticonstrip(nicons)
		End If
		If treeview.icons SetGadgetIconStrip(treeview.gadget,treeview.icons)
		Return treeview
	End Function
End Type

Type gtreeviewnode
	Field parent:tgadget
	Field gadget:tgadget
	Field nodes:gtreeviewnode[]
	
	Method addnode:Int(ntitle:String,nicon:Int=-1)
		Local node:gtreeviewnode = New gtreeviewnode
		node.parent = gadget
		node.gadget = AddTreeViewNode(ntitle,node.parent,nicon)
		Local temp_slot:Int = nodes.length
		nodes = nodes[..temp_slot+1]
		nodes[temp_slot] = node
		Return temp_slot
	End Method
End Type

Type gtextarea Extends ggadget
	Function create:gtextarea(nrect[],nparent:ggadget=Null,nreadonly:Int=False)
		Local textarea:gtextarea = New gtextarea
		Local temp_parent:tgadget = Null
		If nparent <> Null temp_parent = nparent.gadget
		If nreadonly = False
			textarea.gadget = CreateTextArea(nrect[0],nrect[1],nrect[2],nrect[3],temp_parent)
		Else
			textarea.gadget = CreateTextArea(nrect[0],nrect[1],nrect[2],nrect[3],temp_parent,TEXTAREA_READONLY)
		End If
		Return textarea
	End Function
End Type


better ?


Perturbatio(Posted 2007) [#31]
much, a lot easier to understand and to extend.