Skip to content

Commit

Permalink
Doc Style Guide (#3462)
Browse files Browse the repository at this point in the history
* First pass at style guide.

* Remove unused indenting tools.

* Update all C and H files to match style guide vim comment.

* Add vim formatting codes to poncho, taskvine, work_queue Python files.

* Update STYLE.md with standard library modules.
  • Loading branch information
dthain authored Aug 16, 2023
1 parent 0697119 commit df83d1a
Show file tree
Hide file tree
Showing 320 changed files with 433 additions and 273 deletions.
11 changes: 0 additions & 11 deletions .clang-format

This file was deleted.

115 changes: 115 additions & 0 deletions STYLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Coding Style in CCTools

The core of CCTools is written in C, while we also have a number of
libraries and tools for end user access written in Python.

No style guide will exhaustively cover all situations, and there
may be valid reasons to deviate from these suggestions.
Nonetheless, strive to match the existing style of the code,
for the benefit of readers that follow you

## C Style Guidelines

### C Module Design

C source code should be broken into modules, each of which defines a
set of related operations on a common structure that can be reused.
Keep the names of files, structures, and functions ruthlessly consistent.

For example, if you are defining a module for slicing cheese:
- The interface should be described in `cheese_slicer.h`
- The implementation should be given in `cheese_slicer.c`
- The object should be a `struct cheese_slicer`
- The functions operating on `cheese_slicer` should begin with the name `cheese_slicer` and accept a first argument of `struct cheese_slicer`
- The structure should be created by functions like this:
```
struct cheese_slicer * cheese_slicer_create( ... );
void cheese_slicer_delete( struct cheese_slicer *s );
```
- Functions and variables that are private to the module should be marked as `static`, not mentioned in the `.h` file, and may have names without the
module prefix.

### C Utility Modules

Please familiarize yourself with the [many utility modules](https://cctools.readthedocs.io/en/stable/api/html/taskvine__json_8h.html)
that serve as our extended "standard library". Use them instead of rolling your own from scratch:

- Data Structures:
[set](https://cctools.readthedocs.io/en/stable/api/html/set_8h.html)
[list](https://cctools.readthedocs.io/en/stable/api/html/list_8h.html)
[hash_table]((https://cctools.readthedocs.io/en/stable/api/html/hash_table_8h.html)
[itable](https://cctools.readthedocs.io/en/stable/api/html/itable_8h.html)
- Network Access:
[link (TCP)](https://cctools.readthedocs.io/en/stable/api/html/link_8h.html)
[datagram (UDP)](https://cctools.readthedocs.io/en/stable/api/html/datagram_8h.html)
[domain_name_cache (UDP)](https://cctools.readthedocs.io/en/stable/api/html/domain_name_cache_8h.html)
- File Manipulation:
[path](https://cctools.readthedocs.io/en/stable/api/html/path_8h.html)
[full_io](https://cctools.readthedocs.io/en/stable/api/html/full_io_8h.html)
[sort_dir](https://cctools.readthedocs.io/en/stable/api/html/sort_dir_8h.html)
[mkdir_recursive](https://cctools.readthedocs.io/en/stable/api/html/mkdir_recursive_8h.html)
[unlink_recursive](https://cctools.readthedocs.io/en/stable/api/html/unlink_recursive_8h.html)
[trash](https://cctools.readthedocs.io/en/stable/api/html/trash_8h.html)
- JX (JSON Extended) Manipulation:
[jx](https://cctools.readthedocs.io/en/stable/api/html/jx_8h.html)
[jx_parse](https://cctools.readthedocs.io/en/stable/api/html/jx_parse_8h.html)
[jx_print](https://cctools.readthedocs.io/en/stable/api/html/jx_print_8h.html)
[jx_eval](https://cctools.readthedocs.io/en/stable/api/html/jx_eval_8h.html)
- String Handling:
[stringtools](https://cctools.readthedocs.io/en/stable/api/html/stringtools_8h.html)

In particular, we make extensive use of `string_format` to construct and dispose of variable length strings like this:
```
char *mydatapath = string_format("%s/%d/data",mypath,day);
...
free(mydatapath);
```

### C Indenting

Code should be indented like this using hard tabs:

```
int cheese_wheel_slice( struct cheese_wheel *c, int nslices )
{
if( ... ) {
while( ... ) {
...
}
} else {
...
}
}
```

### C Indenting Configuration

If you use vim, the basic indenting setup is given by a comment at the bottom of each file:
```
/* vim: set noexpandtab tabstop=8: */
```

If you use emacs, put the following in `$HOME/.emacs.d/init.el` to achieve the same effect:

```
; Force indentation with a hard tab instead of spaces.
(setq-default indent-tabs-mode t)

; For display purposes, a tab is eight spaces wide
(setq-default tab-width 8)

; Each indentation level is one tab.
(defvaralias 'c-basic-offset 'tab-width)
```

## Python Style Guidelines

TBA

### Python Indenting Configuration

If you use vim, the basic indenting setup is given by a comment at the bottom of python source files:

```
# vim: set sts=4 sw=4 ts=4 expandtab ft=python:
```
2 changes: 1 addition & 1 deletion batch_job/src/batch_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,4 @@ int batch_fs_unlink (struct batch_queue *q, const char *path)
return q->module->fs.unlink(q, path);
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_blue_waters.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,4 @@ const struct batch_queue_module batch_queue_blue_waters = {
},
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_chirp.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,4 @@ const struct batch_queue_module batch_queue_chirp = {

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,4 +708,4 @@ const struct batch_queue_module batch_queue_slurm = {
},
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_condor.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,4 @@ const struct batch_queue_module batch_queue_condor = {
},
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_dryrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,4 @@ const struct batch_queue_module batch_queue_dryrun = {
},
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ struct batch_queue {

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_k8s.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,4 +721,4 @@ const struct batch_queue_module batch_queue_k8s = {
},
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_k8s_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ main()\n\
}\n\
\n\
main\n\
# vim: set noexpandtab tabstop=4:\n\
# vim: set noexpandtab tabstop=8:\n\
";
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_local.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ const struct batch_queue_module batch_queue_local = {
},
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_mesos.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,4 @@ const struct batch_queue_module batch_queue_mesos = {
},
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_mpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,4 +732,4 @@ void batch_job_mpi_setup( const char *debug_file_name, int manual_cores, int man

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_vine.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,4 @@ const struct batch_queue_module batch_queue_vine = {
},
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_job_work_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,4 @@ const struct batch_queue_module batch_queue_wq = {
},
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,4 @@ char * batch_task_generate_id(struct batch_task *t) {
return xxstrdup(t->hash);
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ void batch_task_set_info(struct batch_task *t, struct batch_job_info *info);
char * batch_task_generate_id(struct batch_task *t);

#endif
/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,4 @@ char *batch_wrapper_expand(struct batch_task *t, struct jx *spec) {
return result;
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/batch_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ char *batch_wrapper_write(struct batch_wrapper *w, struct batch_task *t);
char *batch_wrapper_expand(struct batch_task *t, struct jx *spec);

#endif
/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/mesos_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ void mesos_task_delete(struct mesos_task *mt)
free(mt);
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/mesos_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ void mesos_task_delete(struct mesos_task *mt);

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/vine_factory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1579,4 +1579,4 @@ int main(int argc, char *argv[])
return 0;
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion batch_job/src/work_queue_factory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1637,4 +1637,4 @@ int main(int argc, char *argv[])
return 0;
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
6 changes: 0 additions & 6 deletions cctools.indent

This file was deleted.

2 changes: 1 addition & 1 deletion chirp/src/chirp_acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,4 +987,4 @@ int chirp_acl_init_reserve(const char *path, const char *subject)
}
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ int chirp_acl_whoami(const char *subject, char **esubject);

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,4 @@ INT64_T chirp_alloc_mkalloc(const char *path, INT64_T size, INT64_T mode)
return result;
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ INT64_T chirp_alloc_fstatfs(int fd, struct chirp_statfs *buf);

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ void chirp_audit_delete(struct hash_table *table)
hash_table_delete(table);
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_audit.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ void chirp_audit_delete(struct hash_table *table);

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,4 @@ int main(int argc, char *argv[])
return 0;
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -2175,4 +2175,4 @@ INT64_T chirp_client_job_reap (struct chirp_client *c, const char *json, time_t
return get_result(c, stoptime);
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ INT64_T chirp_client_job_reap(struct chirp_client *c, const char *json, time_t s

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_distribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,4 +831,4 @@ int main(int argc, char *argv[])
return 0;
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,4 +917,4 @@ int cfs_stub_job_schedule(sqlite3 * db)
return ENOSYS;
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,4 @@ extern char chirp_url[CHIRP_PATH_MAX];

#endif /* CHIRP_FILESYSTEM_H */

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_fs_chirp.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,4 @@ struct chirp_filesystem chirp_fs_chirp = {
cfs_stub_job_schedule,
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_fs_chirp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ extern struct chirp_filesystem chirp_fs_chirp;

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_fs_confuga.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,4 @@ struct chirp_filesystem chirp_fs_confuga = {
chirp_fs_confuga_job_schedule,
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_fs_confuga.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ extern struct chirp_filesystem chirp_fs_confuga;

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_fs_hdfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,4 @@ struct chirp_filesystem chirp_fs_hdfs = {
cfs_stub_job_schedule,
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_fs_hdfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ extern struct chirp_filesystem chirp_fs_hdfs;

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_fs_local.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,4 +1117,4 @@ struct chirp_filesystem chirp_fs_local = {
chirp_fs_local_job_schedule,
};

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_fs_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ int chirp_fs_local_resolve (const char *path, int *dirfd, char basename[CHIRP_PA

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_fs_local_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,4 +1127,4 @@ int chirp_fs_local_job_schedule (sqlite3 *db)
return rc;
}

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
2 changes: 1 addition & 1 deletion chirp/src/chirp_fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,4 +733,4 @@ int main(int argc, char *argv[])

#endif

/* vim: set noexpandtab tabstop=4: */
/* vim: set noexpandtab tabstop=8: */
Loading

0 comments on commit df83d1a

Please sign in to comment.