Object Oriented Programming in Tiddlywiki using Pure wikitext

146 views
Skip to first unread message

Mohammad

unread,
Dec 14, 2019, 12:57:07 PM12/14/19
to TiddlyWiki
I am practicing a first level simple object oriented programming in Tiddlywiki!
It is not like C++ or Java but some of the useful feature of OOP can be implemented 
and this make scripting even simpler in Tiddlywiki!


What do you think?


Mohammad

unread,
Dec 14, 2019, 1:40:46 PM12/14/19
to TiddlyWiki

What is an object?

An object is a collection of related data and/or functionality (which usually consists of several variables and functions — which are called properties and methods when they are inside objects.)

In Tiddlywiki a tiddler is an object

Ref
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics

Mark S.

unread,
Dec 14, 2019, 1:41:33 PM12/14/19
to tiddl...@googlegroups.com
Sure, a little.

Any tiddler could be thought of as an object, where the fields are properties.

In terms of inheritance, there's a design pattern for "having a ..." (which I'll call HA). The HA pattern turns out to often be more useful than conventional inheritance. And it can be emulated with transclusion in TW.

tiddler A:

created: 20191214183217169
modified
: 20191214183238380
tags
:
title
: A

My A Text

{{||B}}

tiddler B:

created: 20191214183240503
modified
: 20191214183314068
stuff
: b stuff
tags
:
title
: B

{{!!stuff}}


The invoking tiddler, that "inherits" properties from A and B :

created: 20191214183316677
modified
: 20191214183349224
stuff
: inheritance stuff
tags
:
title
: inheritance

{{||A}}

The tiddler "inherits" (HA inheritance because it "has" a transclusion) from "A", which inherits from "B". Note that B reveals the field "stuff", but back in "inheritance", it's the local field "stuff" that is shown, not the field down in B -- just the way inheritance would work.

Have fun

Mohammad

unread,
Dec 14, 2019, 1:55:16 PM12/14/19
to TiddlyWiki

 Object Properties and Methods

  • The value of an object member can be pretty much anything
  • The data items referred to as the object's properties.
  • The functions that allow the object to do something with that data, are referred to as the object's methods.

In Tiddlywiki tiddler fields act as object properties and macros inside tiddler act as object's methods

Mohammad

unread,
Dec 14, 2019, 2:00:50 PM12/14/19
to TiddlyWiki
Hi Mark,
 Thanks for example! That is true a tiddler is an object here!

In your example I cannot find Tiddler B.

--Mohammad


On Saturday, December 14, 2019 at 10:11:33 PM UTC+3:30, Mark S. wrote:
Sure, a little.

Any tiddler could be thought of as an object, where the fields are properties.

In terms of inheritance, there's a design pattern for "having a ..." (which I'll call HA). The HA pattern turns out to often be more useful than conventional inheritance. And it can be emulated with transclusion in TW.

tiddler A:

created: 20191214183217169
modified
: 20191214183238380
tags
:
title
: A

My A Text

{{||B}}

tiddler B:

created: 20191214183217169
modified
: 20191214183238380
tags
:
title
: A

My A Text

{{||B}}

The invoking tiddler, that "inherits" properties from A and B :

Mark S.

unread,
Dec 14, 2019, 2:11:12 PM12/14/19
to TiddlyWiki

This is a repost, since the prior post was missing "tiddler B"

Mohammad

unread,
Dec 14, 2019, 2:25:03 PM12/14/19
to TiddlyWiki
Wonderful Mark!
It works and nice to see how stuff works!
I got an idea the parent can have many fields BUT children have not!

What is HA? did you coin it?

--Mohammad

Mark S.

unread,
Dec 14, 2019, 2:37:37 PM12/14/19
to TiddlyWiki
HA is "has A ..."

It's a different approach to inheritance, and is sometimes more useful than the traditional "IS A ..." inheritance.

So in traditional inheritance you might have CEO -> IS A -> MANAGER --> IS A --> EMPLOYEE

But then what happens if the company has an external consultant? Where does she fit ?

That's probably not the best example. Oh well ...

Mohammad

unread,
Dec 14, 2019, 2:42:09 PM12/14/19
to TiddlyWiki
I will use this terminology you invented!

Mohammad

unread,
Dec 14, 2019, 2:43:19 PM12/14/19
to TiddlyWiki
Mark
 The HA inheritance can be well used for creating CSS!
I will send an example when a base class can be used and several instances with different properties can be created!


On Saturday, December 14, 2019 at 11:07:37 PM UTC+3:30, Mark S. wrote:

Mohammad

unread,
Dec 14, 2019, 2:52:29 PM12/14/19
to TiddlyWiki
This is a HA inheritance example



Simple Inheritance

14th December 2019 at 10:58pm
basic

This example shows how simple a tiddler can inherits from another tiddler.

Description

A base object here is called btn-base implements css for a button. This tiddler is called the base class.

btn-base

.{{!!btn-class}} {
  background-color: {{!!btn-background}};
  color: {{!!btn-color}};
  text-align: center;
  text-decoration: none;
  display: inline-block;
	border: none;
  padding: 15px 32px;
	font-size: 16px;
}

It contains below fields

btn-base

btn-color
white
btn-class
btn-base
btn-background
#4CAF50

Example

Lets create a button using the button class implemented in btn-base

<$button class="btn-base" >
Press me!
</$button>

That renders as:

Ref
https://www.w3schools.com/css/css3_buttons.asp
https://tiddlywiki.com/prerelease/#ButtonWidget


An Instance Inherits from btn-base

14th December 2019 at 11:15pm
basic

Here two new objects called btn-red and btn-blue are created as bellow

btn-red

{{||btn-base}}

It contains the below fields

btn-red

btn-color
white
btn-class
btn-red
btn-background
red

As it is seen btn-red uses simple transclusion to inherit the CSS defined in the btn-base

  • it creates a new class (btn-red)
  • it uses its own new values for the same fields as defined in the base tiddler.

Examples

Use the new CSS class (objects) for styling new buttons.

<$button class="btn-red" >
Press me!
</$button>

<$button class="btn-blue" >
Press me!
</$button>

That renders as:

Remarks
all settings for new buttons are from btn-base
  • new object has its own class name
  • new object has its own properties value
Ref
https://www.w3schools.com/css/css3_buttons.asp
https://tiddlywiki.com/prerelease/#ButtonWidget

TonyM

unread,
Dec 14, 2019, 7:09:53 PM12/14/19
to TiddlyWiki
Folks

I love this abstract thinking and do it a lot myself.

Keep in mind the same "method" can be applied to more than one tiddler. To me macros and buttons can do this and in some ways transcluding a special tiddler (like an object) via the view template conditionally can apply a method to a tiddler.

My recent use of storyTiddler allows you to coopt current tiddler as a parameter to a "method" e.g.
{{Param||methodtiddler}} in wich current tiddler becomes Params tiddler has the login and the real current tiddler is in storyTiddler variable. You can access all fields on the storytiddler, or the param tiddler and with and additional variable the methodtiddlers fields.

One coding practice of mine is to avoid the use of the text field on working tiddlers to reserve it for notes so I have to use the view template to display tiddler content.

Of interest with method tiddlers that have wiki text code in them you can define macros, introduce styles, wiki text and widgets in a single tiddler.

I am currently researching code patterns to ensure this approach is comprehensive and without gaps.

One gap I am working on is automating the setting some fields based on a value in a variable for widgets that only accept fields or text references. To do this I need to use the open tiddler trigger.

Another endeavour of mine is to make use of existing triggers usually in existing buttons to trigger additional actions to reduce the need for additional triggers the user needs to pull. I am somewhat slowed down on this because its similar but different to Jeremy s project to allow widgets to have custom actions.


Regards
Tony

Mohammad

unread,
Dec 14, 2019, 10:50:52 PM12/14/19
to TiddlyWiki
Hi Tony!
A great example of inheritance and object type programming is TiddlyTables by Alan Aldrich!


On Sunday, December 15, 2019 at 3:39:53 AM UTC+3:30, TonyM wrote:
Folks

I love this abstract thinking and do it a lot myself.

Keep in mind the same "method" can be applied to more than one tiddler. To me macros and buttons can do this and in some ways transcluding a special tiddler (like an object) via the view template conditionally can apply a method to a tiddler.

My recent use of storyTiddler allows you to coopt current tiddler as a parameter to a "method" e.g.
{{Param||methodtiddler}} in wich current tiddler becomes Params tiddler has the login and the real current tiddler is in storyTiddler variable. You can access all fields on the storytiddler, or the param tiddler and with and additional variable the methodtiddlers fields.

One coding practice of mine is to avoid the use of the text field on working tiddlers to reserve it for notes so I have to use the view template to display tiddler content.

Of interest with method tiddlers that have wiki text code in them you can define macros, introduce styles, wiki text and widgets in a single tiddler.

I am currently researching code patterns to ensure this approach is comprehensive and without gaps.

One gap I am working on is automating the setting some fields based on a value in a variable for widgets that only accept fields or text references. To do this I need to use the open tiddler trigger.


Alan has used a great solution for this! When you put <<table>> in an empty tiddler, it shows a button to instantiate a new object based on the base class.
 
 

Another endeavour of mine is to make use of existing triggers usually in existing buttons to trigger additional actions to reduce the need for additional triggers the user needs to pull. I am somewhat slowed down on this because its similar but different to Jeremy s project to allow widgets to have custom actions.


Regards
Tony



In my opinion Tiddlywiki has amazing feature but most of them are not documented or under-documented!

--Mohammad
 

TonyM

unread,
Dec 15, 2019, 2:43:17 AM12/15/19
to TiddlyWiki
Mogammad

Yes the table is a great example of a kind of bootstrap or self cloning process.

You say

In my opinion Tiddlywiki has amazing feature but most of them are not documented or under-documented!

I agree many features are under documented, however one of TiddlyWiki's qualities is it "generalist nature" on top of which much can be built. Quite a few things are documented but how to "make use" of them is under-illustrated. The thing is, with "make use of" instructions it is the person who needs the extended instructions, only if they do not work it out for themself or when they know what they are asking for. A lot of solutions out there document there own features and results rather than documenting the code patterns they used to achieve that result. Wiki text is not as self documenting as I would like.

I think editions and some plugins achieve what they set out to do but fail to educate and empower. I know it sounds odd but good design and documentation can sometimes make itself obsolete, because the user learns how to do it them self.

I think we need to document methods, techniques, code patterns and relate them to common designer needs. Only where we find a gap, a need for a convoluted solution or "one solutions solves many", should we be changing the standard distribution.

I think the issue is about empowerment and the right information in the right place. 

TiddlyWiki can already meet so many needs, they are just not all able to be visualised or their to their realisation clear.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages