Services API misuses hash/number (#) symbols

quicksketch - October 28, 2009 - 01:24
Project:Services
Version:7.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:needs review
Description

The services API is littered with completely unnecessary hash symbols. Some properties have hashes, some don't, but there's absolutely no reasoning to which ones have hashes or when/why they're necessary.

It looks like the original API was meant to build on the properties of Form API, but without understanding why FAPI uses hashes. FAPI uses them because it doesn't have a defined structure. Sometimes an array is a form element, sometimes it's a property. Properties are designated with the hash sign.

In the case of Services, it's all properties, just like a lot of other hooks such as hook_menu(), hook_views_default_views(), or hook_action_info(). So services is including these hash symbols for absolutely no reason whatsoever.

This patch applies to the D6 1.x branch (sorry I didn't realize there was a 2.x one, I'd be happy to reroll), and removes all these hash symbols from the API. However to keep it down on size, I did not actually update any of the implementations. Instead, the hash signs are "deprecated" (optional basically) until we can get around to removing them from all the implementations.

AttachmentSize
services_hashes.patch13.97 KB

#1

eaton - October 28, 2009 - 01:35

Agreed. If you have control over an API's data structures, implementing something like 'children' as a defined element key is possible when nesting is required. Hash prefixes should be used for drupal_render()able structures, but are unnecessary for this kind of system.

#2

quicksketch - October 28, 2009 - 03:05
Version:6.x-1.x-dev» 6.x-2.x-dev

I've been updating Flag to use Services (with Amitaibu), and it turns out Flag seems targeted towards the 2.x version of Services. Here's an updated patch for 2.x (not extensively tested). It seems like this problem has just gotten worse in the 2.x version with more hooks and more properties.

AttachmentSize
services2_hashes.patch 25.23 KB

#3

ilo - November 4, 2009 - 18:37

This version includes coder issues fixed, I've tested manually and seems to work fine, at least the services are still there! ;)
Good patch.. I'll start porting to d7

AttachmentSize
services2_hashes_coder.patch 25.29 KB

#4

ilo - November 4, 2009 - 19:32

Sorry, two nasty + characters in the previous patch. Seems that heyrocker also ported the patch to d7, so just in case someone wants to review I've included here.

AttachmentSize
616490_services_hash_coder_d6.patch 23.93 KB
616490_services_hash_coder_d7.patch 23.82 KB

#5

heyrocker - November 4, 2009 - 21:44
Version:6.x-2.x-dev» 7.x-1.x-dev

Committed, thanks! Pushing the version number to make sure we forward-port this to the D7 port.

 
 

Drupal is a registered trademark of Dries Buytaert.