← Back to team overview

dolfin team mailing list archive

TimeDependent is too clever!

 

Hello again!

Here comes another suggestion about the DOLFIN public interface:

Constructing time dependent functions by subclassing from Function and
TimeDependent is very very nice. The way u.sync(t) works by storing a
pointer to t is also very clever. However, I think it is too clever --
most would expect pass-by-value semantics when passing a scalar to a
function. A very simple change could make it a lot clearer what's going
on: Pass a pointer to t instead of a constant reference. This forces the
user to take the address of the scalar, which really shows what's going
on. E.g.

u.sync(&t)

Today I misunderstood the reference nature of sync(t), and wrote code like
this:

while(t < T){
  "compute timestep"
  t += dt
  sync_bc(t)
}

void sync_bc(real t){
  for "all Dirichlet BCs"
     bc.sync(t)  // Pointer to stack memory gets assigned!!!!
}

:-( Of course, no one would be foolish enough to pass a pointer to stack
memory knowingly in such a short lived context.

/Dag



Follow ups