Skip to main content
Post Closed as "Opinion-based" by Bart van Ingen Schenau, gnat, lennon310
Making the question less opinion based. I'm looking for a industry standard name, if there is one.
Source Link

What woulddo you call a functionprocess which transforms objects of complex types into simple objects of primitive types?

My first thought was serialize(...)that I'm "serializing" the complex object, but from what I understand that makes me feel likemeans I'm reducing it down to a string or binary format which cancould be passed over a network. While what I am actually doing is converting a complex object to more primitive types like list, dict, str, int, float, etc. (TheThe context here is python), and I'm trying to rename my function to_dict(...) to something which uses a more idiomatic/industry accepted term.

Currently I'm doing this:

class SomeComplexClass:
    ...

my_complex_obj = SomeComplexClass(...)
simple_obj = to_dict(my_complex_obj)
simple_obj['foo'] = 'bar'
return to_json(simple_obj)

As you see, I'll typically do some final adjustments to the object, then pass this to a library which knows how to convert this into a JSON string, which is passed over the network as HTTP response. This function is used 608 times in our code base.

Here to_dict(...) is doing some heavy lifting, by recursively walking through the complex object and handling corner cases etc., it even supports multiple types of complex objects, even lists of objects.

It is this last part which makes me question the name to_dict(...), because I at some time extended it to support lists as the top level object type. It feels a little silly to do list_of_simple_objects = to_dict(my_list_of_complex_objects), because it then returns a list of dicts.

What are some good alternatives for naming to_dict(...)?

What would you call a function which transforms objects of complex types into simple objects of primitive types?

My first thought was serialize(...), but that makes me feel like I'm reducing it down to a string or binary format which can be passed over a network. While what I am actually doing is converting a complex object to more primitive types like list, dict, str, int, float, etc. (The context here is python).

Currently I'm doing this:

class SomeComplexClass:
    ...

my_complex_obj = SomeComplexClass(...)
simple_obj = to_dict(my_complex_obj)
simple_obj['foo'] = 'bar'
return to_json(simple_obj)

As you see, I'll typically do some final adjustments to the object, then pass this to a library which knows how to convert this into a JSON string, which is passed over the network as HTTP response.

Here to_dict(...) is doing some heavy lifting, by recursively walking through the complex object and handling corner cases etc., it even supports multiple types of complex objects, even lists of objects.

It is this last part which makes me question the name to_dict(...), because I at some time extended it to support lists as the top level object type. It feels a little silly to do list_of_simple_objects = to_dict(my_list_of_complex_objects), because it then returns a list of dicts.

What are some good alternatives for naming to_dict(...)?

What do you call a process which transforms objects of complex types into simple objects of primitive types?

My first thought was that I'm "serializing" the complex object, but from what I understand that means I'm reducing it down to a string or binary format which could be passed over a network. While what I am actually doing is converting a complex object to more primitive types like list, dict, str, int, float, etc. The context here is python, and I'm trying to rename my function to_dict(...) to something which uses a more idiomatic/industry accepted term.

Currently I'm doing this:

class SomeComplexClass:
    ...

my_complex_obj = SomeComplexClass(...)
simple_obj = to_dict(my_complex_obj)
simple_obj['foo'] = 'bar'
return to_json(simple_obj)

As you see, I'll typically do some final adjustments to the object, then pass this to a library which knows how to convert this into a JSON string, which is passed over the network as HTTP response. This function is used 608 times in our code base.

Here to_dict(...) is doing some heavy lifting, by recursively walking through the complex object and handling corner cases etc., it even supports multiple types of complex objects, even lists of objects.

It is this last part which makes me question the name to_dict(...), because I at some time extended it to support lists as the top level object type. It feels a little silly to do list_of_simple_objects = to_dict(my_list_of_complex_objects), because it then returns a list of dicts.

Source Link

What would you call a function which transforms objects of complex types into simple objects of primitive types?

My first thought was serialize(...), but that makes me feel like I'm reducing it down to a string or binary format which can be passed over a network. While what I am actually doing is converting a complex object to more primitive types like list, dict, str, int, float, etc. (The context here is python).

Currently I'm doing this:

class SomeComplexClass:
    ...

my_complex_obj = SomeComplexClass(...)
simple_obj = to_dict(my_complex_obj)
simple_obj['foo'] = 'bar'
return to_json(simple_obj)

As you see, I'll typically do some final adjustments to the object, then pass this to a library which knows how to convert this into a JSON string, which is passed over the network as HTTP response.

Here to_dict(...) is doing some heavy lifting, by recursively walking through the complex object and handling corner cases etc., it even supports multiple types of complex objects, even lists of objects.

It is this last part which makes me question the name to_dict(...), because I at some time extended it to support lists as the top level object type. It feels a little silly to do list_of_simple_objects = to_dict(my_list_of_complex_objects), because it then returns a list of dicts.

What are some good alternatives for naming to_dict(...)?