Fictional API

Purely for fun; how would you create an API to set the operation status of a business?

Objective-C like

[[business [property atAddress:@"台灣946屏東縣恆春鎮西門路121號"]] setOperationalStatus: operationalStatus.openForBusiness];

Xojo like

business( property.atAddress( "台灣946屏東縣恆春鎮西門路121號" ) ).operationalStatus = operationalStatusValues.openForBusiness

Obj-C isnt known for being “terse” :stuck_out_tongue:

The proposed Xojo API looks similarly verbose esp with casts and nested function calls

1 Like

This is only my idea on an API design, I’d be interested to see anyone else’s ideas for an API to set the operational status of business, I don’t care what programming language you use.

It’s purely for fun, I often tease my non-programmer buddies by saying something like this. In this case, it was to say that our favorite breakfast place is open this morning :smiley:

In the spirit of defining the type of swallow: what do you mean, a DesktopBusiness?

1 Like

well … best include a try catch for Xojo :stuck_out_tongue:
suppose property AtAddress ISNT a business but a person’s residence instead ? probably an illegal cast exception results
or worse there is no property at the address (the address is bogus) ?
now a nil object exception

try
  business( property.atAddress( "台灣946屏東縣恆春鎮西門路121號" ) ).operationalStatus = operationalStatusValues.openForBusiness
catch ice as IllegalCastException
catch noe as NilObjectException
end try

So now you might need nullables :stuck_out_tongue:
Which Xojo doesnt support and I’m sure neither do your buddies :stuck_out_tongue:

I’m sure someone could write the Swift for the if let version to test all this

:man_shrugging:

2 Likes

maybe something like

 if let business = business.AtAddress( "台灣946屏東縣恆春鎮西門路121號" ) {
    business.operationalStatus = operationalStatusValues.openForBusiness 
 }  

where business.AtAddress returns nil if the property address doesnt exist (bogus address) or is not a business(residence etc)

now try & explain that one to your buddies :stuck_out_tongue:

1 Like

That’s pretty neat, I didn’t know you could do that in Swift! I wonder if you could do that in Obj-C?

I think I mixed in some Xojo with my Obj-C as I know don’t think you cast like that at all. I looked it up, you don’t :frowning:

(business *)[property atAddress:@"台灣946屏東縣恆春鎮西門路121號"]

It’s late and my brain isn’t at its best but I assume what is going on with your example is it’s setting status of a particular business location to open.

My current gig is 100% C# and so my brain would tend to go here:

if (entity.HasLocationAt(address, out addressId)) {
    entity.Location[addressId].OperationalStatus = OperationalStatus.OpenForBusiness;
}

That assumes entity is some sort of instance of a class that describes a business and the locations it is at, and that address is an instance of a class that describes a particular physical location address.

1 Like

I think you’d have to do it differently in Obj-C
Since Obj-C probably represents a Business as

    Business *business ;

so you test null differently
You can put type annotations on them
Its discussed in this post

but this seems designed to make it easier for SWIFT to interoperate
Not so much to make Obj-C support nullables any differently

So “isKindOfClass” will return YES if the object is valid and it’s class is that of the class being tested or a subClass of it.

property *breakfastResturant = [property atAddress(@"台灣946屏東縣恆春鎮西門路121號")];
if( !breakfastResturant ) {
    printf( "The Address isn't in our database.\n");
} else if( [breakfastResturant isKindOfClass:[business class]] ) {
    [(business *)breakfastResturant setOperationalStatus:operationalStatus.openForBusiness];
} else {
    printf( "The Address isn't a business.\n");
}

I think that should do it…

heck, does the value exist? :slight_smile:

It’s an enum… :slight_smile: