Clownf...ssIntro(3pm)

πŸ“¦
version 0.8.0 Β· 3 versions
, in fedora 43, fedora 44

✨ Clownf...ssIntro(3pm) β€” like, the whole vibe πŸ’…

okay bestie, welcome to Clownfish::Docs::ClassIntro β€” this is the page about working with Clownfish classes in C. yes, C. yes, in this economy. let's go πŸ¦‹


πŸŽ€ NAME πŸŽ€

Clownfish::Docs::ClassIntro β€” working with Clownfish classes in C. that's the whole assignment, periodt.


🌸 DESCRIPTION 🌸

🧚 Inititalizing Clownfish parcels

every single Clownfish parcel has to be initialized before you use it. no skipping, no "it'll be fine", it will not be fine. the init function is named {parcel_nick}_bootstrap_parcel and it takes no arguments β€” zero, none, it's giving low-maintenance queen πŸ‘‘

example:

cfish_bootstrap_parcel();

slay. that's it. that's the whole ritual.


🌈 Including the generated header file

so if you wanna use Clownfish classes from C code, you must include the header file that the Clownfish compiler generates. the name of the C header is derived from the name of the Clownfish .cfh header. you can also find it in the class documentation if you're ever like "wait where is it" πŸ™ˆ

usually you wanna define the β€œshort name macro” before including a Clownfish header. its name comes from the parcel nickname and it looks like {PARCEL_NICK}_USE_SHORT_NAMES. once that short name macro is in effect, you literally don't have to worry about parcel prefixes anymore. iconic behaviour, honestly πŸ’…

example:

#define CFISH_USE_SHORT_NAMES

#include <Clownfish/String.h>
#include <Clownfish/Vector.h>

πŸ‘‘ Function and method prefixes

Clownfish classes can have a β€œnickname” β€” basically a shorter version of the class name, used as the prefix for functions and methods. you can find the nickname in the class documentation. it's in there, bestie, go look 🫢

for example, the String class has the nickname Str.


πŸ¦‹ Creating objects

a Clownfish object is an opaque struct referenced by pointer. mysterious. elusive. main character energy, honestly ✨

most classes come with one or more constructors. at the C level, a constructor is just an β€œinert” function of a class that returns a new object. and in Clownfish parlance, an inert function is any function in a class that isn't a method β€” think static methods in Java, or static member functions in C++. so like, the chill non-method ones 😌

example:

// Notice the use of nickname "Str" in the constructor prefix.
String *name = Str_newf("%s %s", first, last);

πŸ’– Calling methods

calling methods is straightforward, no cap. the invocant is always passed as the first argument. always always.

// Notice the use of nickname "Str" in the method prefix.
size_t len = Str_Length(name);

and hey β€” method names always start with an uppercase letter. lowercase method names are simply not a thing here, so don't even try it πŸ’€


πŸ’œ Memory management

Clownfish uses reference counting to manage memory. this is the part where you pay attention, bestie, because leaking memory is not cute 🫢

constructors β€” but also some methods β€” return an β€œincremented” object. if you're done with an incremented object, you must decrease its reference count, otherwise you leak memory. use the DECREF macro to release an object:

DECREF(name);

some other methods return non-incremented objects. if you wanna keep a reference to one of those, you must increase its reference count using the INCREF macro, so it doesn't get destroyed too early:

obj = INCREF(obj);
⚠️ this invocation of INCREF must be matched by a DECREF when you're done with the object. matched. like a set. don't leave it hanging 😭

some methods β€” for example in container classes β€” take β€œdecremented” objects as arguments. from the caller's perspective, passing a decremented argument is the same as passing a non-decremented argument and then calling DECREF afterwards. usually this saves you a DECREF call in the calling code, which is nice. but sometimes it has to be compensated with an INCREF. balance, bestie. it's all balance 🧚


🌟 Further reading

  • Building Clownfish projects in C environments
  • Writing Clownfish classes

and that's the page!! brought to you by perl v5.42.3, dated 2026-09-02 β€” mwah, take care of your reference counts and hydrate πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from