PDA

View Full Version : Telling the difference between COFFEE and Python?


Navstar
12-14-2012, 04:21 PM
I'm not a programmer by any means. But what are some visual clues to tell if a script is written in Python or COFFEE?

(And just for fun, does COFFEE actually stand for something?)

Per-Anders
12-15-2012, 02:53 AM
For a non coder you can identify COFFEE as separate from Python visually several ways.

Firstly in COFFEE the lines end with a semicolon ; while in Python they do not.

Python requires importing of various libraries before it will function, while COFFEE is a fully integrated language and so these are implicit, as such at the top of any Python script you will find some lines such as

import c4d
from c4d import gui

COFFEE variables must be declared before use with the "var" keyword i.e.

var index = 0;

While in python no var keyword is necessary

index = 0

Conversely function calls in Python must start out with the "def" keyword

def someFunction(self, a, b):

While in COFFEE no such keyword is required

main(a,b) {

COFFEE code uses curly bracket braces around blocks of code


if (a > 10)
{
b += a;
a = 0;
}


While Python uses a colon to designate branching into the next cocde block and the block is simply indented with no braces


if a > 10:
b = b + a
a = 0


Because of this use of whitespace Python scripts have a different visual look with a lot more indentation than COFFEE scripts.

Comments in COFFEE use the double forward slash // while in python they start with a hash #.

Because Python uses a library to access Cinema's function calls and because the default method of importing that library is simply "import c4d" then you will see a lot of "c4d.SOME_VALUE" or "c4d.SomeFunction()" in Python while in COFFEE you would simply see "SOME_VALUE" or "SomeFunction()" instead without the explicit "c4d" in front.

Anyhow, that's a few ways to spot the difference, there are many other differences between the languages that show up visually, but these should be more obvious as far as tells go when quickly scanning the languages if you've no experience of them before.

littledevil
12-15-2012, 07:07 PM
(And just for fun, does COFFEE actually stand for something?)

i don't think C.O.F.F.E.E is an actual acronym, it has been introduced at a time, when some maxon employee thought it would be extra funny to name everything in a coffee releated way in cinema 4d (c.o.f.f.e.e, espresso, cappuccino). on top of that it seems to be a reminiscence of java script, which can be seen as the archetype of the coffee language (typeless, c alike snytax ).

ps : the most forward way would be the file extension, coffee scripts are meant to be called *.cof, while python scirpts should be named *.py . however this identification isn't 100% safe, as the extension isn't obligatory and threfore the author could use any extension for his script.

Scott Ayers
12-16-2012, 08:02 PM
Another glaring visual difference is Coffee uses the pointer symbol: ->
While Python uses the dot symbol: "."

-ScottA

gdogfunk
12-17-2012, 07:17 PM
I was trying to rig a steam engine governor recently and used xpresso to get the Y position of my governor moving down based on crankshaft rotation, BUT I wanted to limit the distance of the Y position. A coding friend suggested getting the object moving and using an IF statement to check for Y position and limit the Y position based on max angle, etc. I liked the idea but got stuck on whether to use coffee or python and then how to implement it into the xpresso setup I already had. Which is the better scripting tool for the job in this case?

Thanks!

Ryan

littledevil
12-17-2012, 08:03 PM
both scripting languages are equally suiteable, but by way you are asking i suppose you
are more the non coding type, so a visual scripting language would be your tool of choice,
which would be Xpresso in c4d. you would just need two objects nodes of the object
you want to limit, a condition node (if) and a compare node (greater as, smaller as ...).
as a simple example , limit the y position to 50:

http://www10.pic-upload.de/17.12.12/u66ysgqq4ug6.gif

aside from that, i am not an animator, but i think constraint tag and the hinge object are also made for this case.

edit : open the picture in a new browser tab, if you have problems reading it.

CGTalk Moderation
12-17-2012, 08:03 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.