Skip to content

decompiler: less concise, but also more useful, variable naming scheme #5728

Open
@slippycheeze

Description

@slippycheeze

Is your feature request related to a problem? Please describe.
Looking at this code, it is hard to tell what the actual types being addressed are:

ItemReplicaInfo* pIVar3, pIVar12;
Item** ppIVar6, ppIVar8, ppIVar13, ppIVar15;
Item*  pIVar4;
Object* pOVar10;

pIVar3 = pVVar1.head;
lVar7 = (longlong)(((longlong)pVVar1.tail - (longlong)pVVar1.head) / 0x140);
ppIVar6 = ppIVar13;
ppIVar8 = local_70.field2_0x8;
pOVar10 = local_70.field1_0x0;
pIVar12 = pVVar1.tail;
ppIVar15 = ppIVar13;
if (lVar7 != 0) {
    do {
        pIVar4 = GAME::Item::CreateItem(pIVar3 + (longlong)ppIVar6);

The current naming scheme is fairly concise, which is nice for small functions, but doesn't scale well to larger functions. Those 8 variable names are identical for 80+ percent of their content; very low information to character ratio, IMO.

This is amplified because humans tend to cluster type names, so Item, ItemReplica, and ItemReplicaInfo are routinely used together. Ditto "database table" type classes that use multiple vector<T> members as "columns" and index by integer ID to work with a single row of data: pVVar{N} has radically different types for every N, but the code doesn't distinguish them at all.

Describe the solution you'd like
I'd like to be able to have the decompiler use a "verbose" naming scheme that was less information-lossy, at least once the function exceeded a certain size limit. (Personally, I'd be fine with very verbose names all the time, but I know others prefer different, and I do as well, contextually.)

Every programmer, and their dog, has a naming scheme to suggest, but I have two concrete suggestions for how to handle this "placeholder" naming problem following; examples of the code from above

just say it all: the naming pattern is DataType.getName() unmodified; maximally verbose,
but also preserves 100 percent of information about the type of the variable. annotation for pointer variables and append a number as presently.

// JUST SAY IT ALL
ItemReplicaInfo* pItemReplacaInfo3, pItemReplacaInfo12;
Item** ppItem6, ppItem8, ppItem13, ppItem15;
Item*  pItem4;
Object* pObject10;

pItemReplacaInfo3 = pVVar1.head;
longlong7 = (longlong)(((longlong)pVVar1.tail - (longlong)pVVar1.head) / 0x140);
ppItem = ppItem13;
ppItem8 = local_70.field2_0x8;
pObject10 = local_70.field1_0x0;
pItemReplacaInfo12 = pVVar1.tail;
ppItem15 = ppItem13;
if (lVar7 != 0) {
  do {
    pItem4 = GAME::Item::CreateItem(pItemReplacaInfo3 + (longlong)ppItem6);

long abbreviation style: the naming pattern is "extract the first letter of every 'word' in the name", such that we get: ItemI, ItemReplicaInfoIRI, etc. This preserves more information, but also demands more "smart" to avoid traps:

ItemReplicaInfo    IRI
itemReplicaInfo    IRI
item_replica_info  IRI or iri  // case folded or not, either way works; if lowercase use `p_` and `pp_`
URL                URL
item_ReplicaInfo   IRI, or ...
ItemReplicaInfo* pIRIVar3, pIRIVar12;
Item** ppIVar6, ppIVar8, ppIVar13, ppIVar15;
Item*  pIVar4;
Object* pOVar10;

pIRIVar3 = pVVarVar1.head;
longlongVar7 = (longlong)(((longlong)pVVarVar1.tail - (longlong)pVVarVar1.head) / 0x140);
ppI = ppIVar13;
ppIVar8 = local_70.field2_0x8;
pOVar10 = local_70.field1_0x0;
pIRIVar12 = pVVarVar1.tail;
ppIVar15 = ppIVar13;
if (lVarVar7 != 0) {
  do {
    pIVar4 = GAME::Item::CreateItem(pIRIVar3 + (longlong)ppIVar6);

Describe alternatives you've considered
I could keep manually renaming these things, but really... ouch.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions