Skip to content

Goal of Analyzer

Louis Kueh edited this page Jan 20, 2019 · 13 revisions

Why are you doing it?

What does the analyzer do?

Tackles heuristics that are hard to track down, targeted especially at beginners.

Each will be labelled

  • easy
  • medium
  • hard

Depending on the expected difficulty of implementation. Each seperate analyzer will target areas to help the programmer write better code and understand what they are writing. The idea is that the programmer can choose the different analyzers they wish to run. For example, a seasoned functional programmer would not appreciate a Learning analyzer, but could find the Smart Sensing analyzer useful.

  • Readability, Typography Analyzer

  • Learning Analyzer

    • Example of problems
    • Obscure compiler/parsing errors
  • Smart sensing, context

Analyzers

Readability, Typography (easy)

This analyzer deals with how the code is written with emphasis on readability.

  • linelegth
  • max chars
  • nesting of statements
  • number of parameters to a function
  • lambda function to be removed

Learning, tutorial hints (medium)

Why?

Functional programming exists within several procedural languages such as Javascript and Lambdas in modern C++ and therefore would be incredibly useful.

These give the user insight into why something might be better written a certain way with equal semantic meaning. These hints will assume the user is unfamiliar with functional langauges.

Alongside explanations, a graphical animation for main functions of F# (fold, reduce, etc) can be displayed to the user. In many cases, learning via a animated images instead of text can boost understanding

Often compiler hints are obscure and the solution is quite hard to find, especially for programmers new to the language. Upon compiler errors, the analyzer will determine (if any) of these errors occur, and highlight to the user the possible correct solution. E.g. perhaps you meant this?

What is meant by obscure error messages?

What exists already, and how is this different?

The learning Analyzer differs from other analyzers out there in the sense that .. NEED TO RESEARCH below in that most of the things listed would be clear to any intermediate F# Programmer from their knowledge of F# or experience when writing code.

NEED TO RESEARCH

Example of specific problems

Some of these are from FSharp fun and profit, my own experience, as well as common errors on the web. These are all referenced.

Lists and tuples

Lists uses ; to seperate items, where as tuples use , to seperate elements.

If the user calls a list function (e.g. map) on a tuple then it is likely the the programmer meant it to be a list.

image

let list1 = [1,2,3]    // wrong! This is a ONE-element list containing 
                       // a three-element tuple
let list1 = [1;2;3]    // correct

type Customer = {Name:string, Address: string}  // wrong
type Customer = {Name:string; Address: string}  // correct

Dont use mutable/loops!

As a beginner a common mistake when starting out is using mutable/loops in order to follow more procedural approaches.

Function signatures

This section will explain to the user why function signatures are as they are e.g. why arguments passed into a function really only have one argument, currying int -> int -> int

If you are trying to create a function pointer or delegate, watch out that you don’t accidentally create a simple value that has already been evaluated.

If you want a parameterless function that you can reuse, you will need to explicitly pass a unit parameter, or define it as a lambda.

let reader = new System.IO.StringReader("hello")
let nextLineFn   =  reader.ReadLine()  //wrong
let nextLineFn() =  reader.ReadLine()  //correct
let nextLineFn   =  fun() -> reader.ReadLine()  //correct

let r = new System.Random()
let randomFn   =  r.Next()  //wrong
let randomFn() =  r.Next()  //correct
let randomFn   =  fun () -> r.Next()  //correct

Examples of F# Compiler Errors

These examples are identical to Example of specific problems. In this section common compiler errors that are obscure (for beginners) are targeted. Instead of targeting common problems, here the error messages of each FS00X compiler errors are broken down into the possible causes and solution.

The biggest section is FS0001: The type ‘X’ does not match the type ‘Y’, with the majority of common problems for beginners having this error.[REF]

Smart sensing, context, Analyzer

  • White space
  • Naming of varaiables

Clone this wiki locally