TBF and API design.. (boolean/int trap)

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/osmocom-net-gprs@lists.osmocom.org/.

Holger Hans Peter Freyther hfreyther at sysmocom.de
Sat Aug 24 17:28:39 UTC 2013


Good Evening,

I started a branch to add a basic structure to the TBF handling. The
reasons why I am doing this is for another lengthy email. I just came
across a piece of code and would like to create some awareness:

int write_immediate_assignment(bitvec * dest, uint8_t downlink, uint8_t ra,
        uint32_t ref_fn, uint8_t ta, uint16_t arfcn, uint8_t ts, uint8_t tsc,
        uint8_t tfi, uint8_t usf, uint32_t tlli, uint8_t polling,
        uint32_t fn, uint8_t single_block, uint8_t alpha, uint8_t gamma,
        int8_t ta_idx);

and invocations like:

        if (sb)
                plen = write_immediate_assignment(immediate_assignment, 0, ra,
                        Fn, qta >> 2, bts->trx[trx].arfcn, ts,
                        bts->trx[trx].pdch[ts].tsc, 0, 0, 0, 0, sb_fn, 1,
                        bts->alpha, bts->gamma, -1);
        else
                plen = write_immediate_assignment(immediate_assignment, 0, ra,
                        Fn, tbf->ta, tbf->arfcn, tbf->first_ts, tbf->tsc,
                        tbf->tfi, tbf->dir.ul.usf[tbf->first_ts], 0, 0, 0, 0,
                        bts->alpha, bts->gamma, -1);

With the above method and two invocations it is difficult to get all
arguments right and it is a strong argument against ever writing code
like this. With C++ one could create overloads that take the bts and
tbf as parameters. Or if one really only wants to have a single method
use a struct to pass the parameters. This has the benefit of naming
the parameters and will certainly require the same amount of stack
space as the current option.

So please, don't write methods like the above as they make maintaining
the code more difficult than it needs to be.

holger

-- 
- Holger Freyther <hfreyther at sysmocom.de>       http://www.sysmocom.de/
=======================================================================
* sysmocom - systems for mobile communications GmbH
* Schivelbeiner Str. 5
* 10439 Berlin, Germany
* Sitz / Registered office: Berlin, HRB 134158 B
* Geschaeftsfuehrer / Managing Directors: Holger Freyther, Harald Welte





More information about the osmocom-net-gprs mailing list