# How to organize my functions?

**URL:** <https://forums.fsharp.org/t/how-to-organize-my-functions/1165>\
**Category:** General\
**Tags:** beginners\
**Created:** [January 9, 2020, 11:04pm UTC](https://forums.fsharp.org/t/how-to-organize-my-functions/1165 "2020-01-09T23:04:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhoweaa](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@jhoweaa](https://forums.fsharp.org/u/jhoweaa)\
**Post date:** [January 9, 2020, 11:04pm UTC](https://forums.fsharp.org/t/how-to-organize-my-functions/1165/1 "2020-01-09T23:04:42Z")

</div>

I’m new to F# and functional programming in general. I’ve been doing O-O for many years and I have an instinctive feeling for how to organize my code. With F#, I’m not so sure. I feel like I’m just littering my files with a bunch of functions, organized only such that all the references work out. I’ve done some organizing of functions in to namespaces and modules, but I haven’t developed a good feel for the best way to organize, or even when to organize. Can anyone offer any tips on dealing with code organization? When to use namespaces, modules within namespaces, etc.? Are there some good guidelines?

Thanks!

---

<div class="post-metadata">

**Author:** ![Christophe](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/christophe/32/698_2.png) [@Christophe](https://forums.fsharp.org/u/Christophe)\
**Post date:** [January 11, 2020, 8:45am UTC](https://forums.fsharp.org/t/how-to-organize-my-functions/1165/2 "2020-01-11T08:45:50Z")

</div>

**Firstly, you should remember that F# requires files (and code within a file) to be in _dependency order._**  
And a simple tip that I always do:

```auto
namespace A
type B
module B =
// functions with type B

```

Also there is a [post](https://fsharpforfunandprofit.com/posts/recipe-part3/) about it on [F# for fun and profit](https://fsharpforfunandprofit.com/)

---

<div class="post-metadata">

**Author:** ![jhoweaa](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@jhoweaa](https://forums.fsharp.org/u/jhoweaa)\
**Post date:** [January 12, 2020, 3:16pm UTC](https://forums.fsharp.org/t/how-to-organize-my-functions/1165/3 "2020-01-12T15:16:53Z")

</div>

Thanks for the information and the pointer to the blog post on F# for fun and profit. There is so much good information on that site and I must have overlooked this particular post.

---

<div class="post-metadata">

**Author:** ![Prash](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/prash/32/815_2.png) [@Prash](https://forums.fsharp.org/u/Prash)\
**Post date:** [February 5, 2020, 1:16pm UTC](https://forums.fsharp.org/t/how-to-organize-my-functions/1165/4 "2020-02-05T13:16:37Z")

</div>

That is an option but I prefer:

```auto
module A.B // produces module B within namespace A

// types ...

// functions ...

```

This doesn’t enforce that functions can’t be defined in the section for types but it’s easy to do that by convention and to fix by moving code. It also means you don’t have to add another level of indentation to all your functions.

F# for Fun and Profit is a great resource but it contains many recommendations and suggestions that aren’t considered to be a best practice or necessary practice by the F# community as a whole, or even the author currently as his views have evolved over time (this is my understanding through hearsay, and I know Scott, he is a lovely man 🙂).
