Hi, just embarking on my first Ocaml program after getting half way through “Real World Ocaml” and getting to critical mass with the language. Before I ingrain too many bad habits could I get some constructive criticism of the below.
open Core
open User
(* This code reads from a CSV file of user details and create Jabber for Windows softphone profiles in
Cisco CUCM via AXL or it will do eventualy if I manage to finish it LOL*)
let user_from_string line = (* TODO: Move this function into the user module*)
let field_list = String.split line ~on:',' in (* TODO: Check there are enough fields so we dont throw an exception*)
{ User.
first_name = (List.nth field_list 0); (* TODO: Is there a nicer way to do this??*)
second_name = (List.nth field_list 1);
user_id = (List.nth field_list 2);
extension = (List.nth field_list 3);
uri = (List.nth field_list 4);
}
let read_file_and_create_users filename =
Printf.printf "Processing file : %s \n" filename;
let lines = In_channel.read_lines filename in
let users = List.map ~f:(fun line -> user_from_string line) lines in
users
let () =
let args = Sys.get_argv () in
let filename = args.(1) in (* TODO Add some error checking incase the file name is missing*)
let users = read_file_and_create_users filename in
let count = List.length users in
Printf.printf "User count : %d \n" count; (* TODO: Create a string_from_user function on User module*)
List.iter users ~f:(fun x -> match x.first_name with
| None -> Printf.printf "%s\n" "unknown"
| Some x -> Printf.printf "%s\n" x
)