PlasmaFAIR / fortitude

A Fortran linter, written in Rust and installable with Python.
MIT License
48 stars 1 forks source link

Prefer `if ... then` over inline `if` #65

Open LiamPattinson opened 2 months ago

LiamPattinson commented 2 months ago

For consistency and readability, prefer this:

if (.not. allocated(x)) then
  allocate (x(n))
end if

over this:

if (.not. allocated(x)) allocate (x(n))
ZedThree commented 2 months ago

This is probably a "pedantic" warning rather than a default one!

LiamPattinson commented 2 months ago

I agree, but I've seen this sort of thing argued in C/C++ style guides, so I think it would make sense to have it as an option

ZedThree commented 2 months ago

I wrote something out arguing that it's different, but then I convinced myself it isn't really!

Maybe if the statement is split over multiple lines it's more dangerous than if it's all on one line. I'm not sure how easy that is to catch

Beliavsky commented 4 days ago

I prefer the one-line if to the block and would therefore prefer that a warning about the one-line if not be turned on by default.