Skip to content

Conversation

@Noremos
Copy link
Contributor

@Noremos Noremos commented Jun 18, 2025

This is also a preparation for the JSON Type implementation

@Noremos Noremos changed the title Merge putDtype and putType, remove duplicate code Merge putDtype and putType; remove duplicated code Jun 18, 2025
Copy link
Member

@asfernandes asfernandes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you not choose better names for methods you created to not duplicate code, I prefer to have the code duplicated.
I understand nothing what the refactored methods do by their names.

@Noremos
Copy link
Contributor Author

Noremos commented Jun 19, 2025

If you not choose better names for methods you created to not duplicate code, I prefer to have the code duplicated. I understand nothing what the refactored methods do by their names.

I tried to follow the style of the original method names. putType and putDtype are not the most transparent names either. So it would be nice if you could suggest alternative names for my methods

@dyemanov dyemanov merged commit 1444312 into FirebirdSQL:master Jul 4, 2025
23 checks passed
}

void DsqlCompilerScratch::putType(const TypeClause* type, bool useSubType)
template<bool THasTableName>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What means THasTableName?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indicates the presence of typeOfTable.* fields in the TypeClause& type. That is, we use blr_column_name (i.e., the table name with typeOfTable) or blr_domain_name (with typeOfName).

Copy link
Member

@dyemanov dyemanov Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd question the need of the T prefix, as it usually means some type used as the template argument, not the variable. Simple HasTableName or maybe IsTypeOfTable is IMHO better readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have some explicit coding style for such cases. The existing one suggests using a single letter, which is not the clearest name possible in this case. Personally, I use the T prefix to make the template argument easier to recognize in the code, especially with if constexpr statements

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd question the need of the T prefix, as it usually means some type used as the template argument, not the variable. Simple HasTableName or maybe IsTypeOfTable is IMHO better readable.

Yes.

DsqlCompilerScratch* makeScratch()
{
auto& pool = *getDefaultMemoryPool();
return FB_NEW DsqlCompilerScratch(pool, nullptr, nullptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why create objects in heap and leak them instead of use local objects and let RAII destruct them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I forgot to fix my raw temporary implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is why I am leaking memory:

protected:
	// DsqlCompilerScratch should never be destroyed using delete.
	// It dies together with it's pool.
	~DsqlCompilerScratch()
	{
	}

I can create a derived class and use it, but I'm not sure if it's safe to delete it, since the DsqlCompilerScratch has a strict prohibition

}

void DsqlCompilerScratch::putType(const TypeClause* type, bool useSubType)
template<bool THasTableName>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd question the need of the T prefix, as it usually means some type used as the template argument, not the variable. Simple HasTableName or maybe IsTypeOfTable is IMHO better readable.

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants