drupal_add_js best practice to include inline code or script file
They are both and the same. The fileparameter you have specified in your second example is the same as the first example as it's the default type.


  type: The type of JavaScript that is to be added to the page. Allowed values are 'file', 'inline', 'external' or 'setting'. Defaults to 'file'.


Source: drupal_add_js

If your question is about whether it's best practice to use inline or file then it depends on your requirements. If you need to load a JavaScript library or a large amount of JavaScript then I would use file type. If you are just loading say some tracking code, or a few lines of JavaScript then I would probably use inline as it's one less HTTP request.