Hyston blog
About • Archive • RSS

Developer diaries: how to break all naming rules in CoffeeScript

2019-02-07 06:02

On my main job we have a project, that contain all kinds of technologies. Mostly it us angularJs or razor pages, but we got also knockout, that works in pair with signalr. This cause many problems and one of the technical debt currently is to replace signalr hubs to ajax calls. But problem is we cant do this at once, we have to support both versions at the time to turn it off, if something goes south. Now coffeescript is packed with checkings, what to call, but problem is that in response from server signalr hub return parameters in camelCase, and ajax return in CamelCase. I got a strong feeling, that if I will add another useSignalR checking, this code will be cursed forewher, so I wrote small function:

replaceAttributesToLowerCase: (object) ->
	for propertyName in Object.keys(object)
		lowerCaseProperty = propertyName.toLowerCase()
		object[lowerCaseProperty] = object[propertyName]
	return object

Rare beauty of javascript flexibility, heh 😎 Also now all parameters are lowercase in whole class, which is severely breaking naming conventions. And it double object size in memory. But in my opinion, all parts of projects, that contain knockout, coffeescript or signalr should be buried.

Next entry → ← Prev entry