End or End Method?

Monkey Forums/Monkey Programming/End or End Method?

Blute(Posted 2011) [#1]
I am new to Monkey and thought I give it a go. I am choosing to use TextMate as my text editor (thanks Matt). Code folding works if I use the "Method...End Method" form but does not work with the "Method...End" form. Monkey seems to work either way. Is there a difference between forms and is one being depreciated?


GfK(Posted 2011) [#2]
There's no difference. Don't know if the longer method is deprecated but that's how I do it as it makes code more readable.


therevills(Posted 2011) [#3]
I actually prefer just "End" ;)

Monkey accepts the following:
* End
* EndMethod
* End Method

Which IMHO is too many... it should only allow one not threeboth!!


Goodlookinguy(Posted 2011) [#4]
It's a code stylistic choice. Also, Monkey doesn't allow "EndMethod." It throws an error for me. Unless that's a bug.


therevills(Posted 2011) [#5]
Opps yeah you are right... I was thinking of BlitzMax and the IFs.

Monkey accepts the following closing commands for IFs:
* End
* EndIf
* End If


ziggy(Posted 2011) [#6]
AFAIK None is deprecated. I preffer the longer form when I don't have to type it all, as it makes code clearer to me.


Blute(Posted 2011) [#7]
Thanks all. Although it is a bit more typing I will stick with the longer form as it seems more 'proper' somehow and code folding works in TextMate.


Jesse(Posted 2011) [#8]
I also think it makes code clearer to me.


therevills(Posted 2011) [#9]
as it seems more 'proper'


Since I code mostly in Java at work I find it less "proper" ;)

In Java "}" is used for "End" for Ifs, Loops, Classes, Methods etc:

Class Foo {
	private int x;

	public void setX(int x)	{
		if (x < 10) {
			this.x = 0
		} else {
			this.x = x
		}
	}
}



Jesse(Posted 2011) [#10]
LOL!

since it's a derive from basic(?) and we have stuff like this:

repeat /until, while/wend, for/next

to me it makes since to follow it with it's corresponding counter part.


therevills(Posted 2011) [#11]
since it's a derive from basic(?) and we have stuff like this:



Yeah that's fine... but lets have one ending for them not two or three:

While .. Wend
While .. End

For .. Next
For .. End

If .. End If
If .. EndIf
If .. End

Method .. End Method
Method .. End

Function .. End Function
Function .. End


I believe that programming languages should be concise as possible...


Jesse(Posted 2011) [#12]
I agree with that!


muddy_shoes(Posted 2011) [#13]
The chances of me going through thousands of lines of code and adding redundant keywords that serve no purpose other than to make it look "more BASIC-y" in some people's eyes is slim to none.


DruggedBunny(Posted 2011) [#14]
Ah, I really like the flexibility; something not frequently offered by many programming languages. I do choose the Method/Function... End construct in Monkey personally (while much preferring Select/End Select, etc), which I seem to recall I wasn't too happy with at first, but, programming something in BlitzMax with an eye on Monkey portability, I'm finding BlitzMax's enforced End XYZ slightly annoying now!

Seriously, though, you can take your pick. That's a good thing, within reason.


Jesse(Posted 2011) [#15]
LOL!
I guess the fix won't be a fix for all solution.
Whatever side Mark decides to go, if he goes, I won't complain. my way is as simple as search and replace others not so simple.


therevills(Posted 2011) [#16]
I think Mark has already decided - Its too late to change Monkey now...

@DruggedBunny, that's one of the reasons why I am coding a BlitzMax target for Monkey ;)


Samah(Posted 2011) [#17]
Just be thankful you aren't forced to use whitespace to declare your blocks like a certain other language...


FlameDuck(Posted 2011) [#18]
since it's a derive from basic(?) and we have stuff like this:
Monkey is derived from BASIC, in the same sense that an F-22 Raptor is derived from a bicycle. Yes the Wright brothers where bicycle repairmen, and yes they did invent the first vehicle capable of sustained, powered, heavier-than-air flight. But that's really where the similarities end. Monkey today has much more in common with more modern languages like Java and Python, than it does with BASIC.

Just be thankful you aren't forced to use whitespace to declare your blocks like a certain other language...
Except that would be awesome, and I definitely think think BRL should take more pointers from Python (or Boo or other YAML-like languages), and less (much less) pointers from languages like Lua for instance (which also erroneously thinks it's a fantastic idea to have different keywords delimit the end of block statements).


Samah(Posted 2011) [#19]
...languages like Lua for instance (which also erroneously thinks it's a fantastic idea to have different keywords delimit the end of block statements).

Last I checked, blocks in Lua always ended with "end" (except "until").


matty(Posted 2011) [#20]
I've become so used to the database language we use at work that uses "End For" and "End While" instead of "Next" and "Wend" that I use it in monkey too....now all my "For" loops end with "End For" (which looks neater to me than "Next"....I was so used to really old basic that for a long time with blitz I used to put the iterator variable after the next which was always disallowed ... eg "For i = 1 to 3 .... some statements ..... Next i"


Foppy(Posted 2011) [#21]
I use "End If" and "End Method", it keeps my fingers from cooling down too much while thinking about the next line of code!