Simplifying bash & repl Use With F#

That prompt… let’s get F# so that we can compile and run a file in about a zillionth of a second from the repl.

First I setup a bash script that would be used to compile and then run the file. I created the file and simply named it “fs”. Inside the file I wrote the following script.

echo "Compiling F#" + $1
fsharpc "$1.fs"
mono "$1.exe"
echo "Running Executable" + $1

I put that in my scripts folder that I have added to my path in my ~/.bash_profile (or bashrc depending on what you’re rolling with).

export PATH="$PATH:~/Codez/scripts"

So now I have the ability to type in the following command and filename and the compile and the executable will be run. It makes for much easier repl usage.

fs theFileNameGoesHere

Got any tips or tricks to running F# somewhere besides Windows? Let me know and I’ll be sure to give you a shout out on Twitter and whenever I’m giving a presentation on hacking F# without Windows.

Why F#, and Why Not Windows

I posted my previous entry and got a few retweets and favorites. One reply came back and made me think, “ah, it might not be obvious why I’d like to have F# on something besides Windows.” Well, here’s a list of why I want to use F# on non-Windows platforms.

  1. F# is a good language. I can’t say the best, since I honestly don’t have enough experience with it or other functional languages to really declare a victory in my opinion. However I’ll be doing some work with Scala, Haskell, and Erlang in the next couple of weeks for testing and use with some upcoming projects.
  2. There are only three technology stacks that will let one spin up an actual application on all of these technologies: OS-X Cocoa, Windows, Linux, Android, and iOS. These two tech stacks are .NET and than the Node.js JavaScript stack – with the latter being purely web based. (Yes, some could argue Adobe’s tools, but I’m not going down that route right now)
  3. With F# I get a clean functional language that I can build native mobile, tablet, or OS apps and all the web services that I want with two advantages over Node.js. The first is the performance edge and can likely be tuned more anyway. Being paired with SignalR one can even get some wicked simple and fast real-time capabilities with minimal code. The second is it takes less F# code to do similar JavaScript things and compute, let me tell you about compute with F#. F# can run things that JavaScript just really can’t measure up to when it comes to compute. But aside from these things, they’re both excellent tools and I wanted to have F# in my tool belt.
  4. There’s always the backup plan of just converting to JavaScript too, if I needed that sort of thing. Check out FunScript.
  5. The community around F# is actually pretty cool, there are good, solid, intelligent, and friendly people in that community. Having a good community of people always makes getting into a new language or related tech much better then when the community consists of asshats or jack ass savants.

Other great things that add to the usefulness of F# include WebSharper.NET MVC 5 and Web API, Nancy API, Suave.io, and there are others.

So those are the reasons I decided to move forward with F#: solid language, provides a solid technical stack with options, it’s functional and clean with extra compute power, and a kick ass community. Of course F# came from the land of Windows and Softies (that’s short for Microsofties, and I didn’t make that up). But F# was handed over to the open source community and currently moves forward autonomously of Microsoft. By proxy of this event, and other culminating events of late, F# can easily run on operating systems besides Windows. I’m not a fan of Windows, and here’s a few snarky (yet very real) reasons why I don’t even want to mess with Windows (except in the situation where I really do want to or need to use Visual Studio).

  1. Windows is still slow. I could go into the reasons, but it tends to build slow, behave slow, be prone to the attention of spammers and such, only in the last X years has it managed security in a half ass decent way, which also leads to slowness, and … oh you get the idea. It’s a slow OS.
  2. It’s flippin’ humongous. Now is this really a problem? Not really, but it’s annoying to force fit it in when I’m doing DevOps work or actually attempting to load Windows related images with it. The OS itself is still a nightmare of gigantic proportions compared to spooling up other systems. If one wants to fight with it, that’s great, I don’t really feel a keen desire to fight with it.
  3. Linux == Smaller footprint, more features, let’s not bring up security, is actually used on major systems, large scale systems and super-computers. Windows has less than 2% market share in that space. Even Microsoft is decreasing their reliance on Windows, offering oodles of Linux options.
  4. Windows doesn’t tend to get, run, or have the bleeding edge tech options built for it. Go look at the open source massive distributed systems applications and other excellent leading platforms and tooling that are leading companies into the future. If Windows is involved at all, it’s often an afterthought. :-/
  5. Windows 8 interface. I’m just going to leave that one right there. I like a lot about it, but I’m with Microsoft, even with Windows 10 they’re not trying to push this UI/UX catastrophe any longer.
  6. SSH not built in. End of story.

Don’t get me wrong, the tooling on Windows for doing Windows specific development and even doing crud apps with lots of business rules is spectacular. I’d even bet that the .NET ecosystem does a better job, sometimes dramatically better, than the Java ecosystem when it comes to those types of applications. I however, haven’t built these style of applications in a long while. Whenever I do, Windows might be a prime option, but otherwise I’ll stick to the operating systems that get me into the coding faster, sooner, and with less resistance.

Outside of Windows there are a lot of great Microsoft tools and technologies that I’d love to have on non-Windows operating systems. One of those is F#. Another is Visual Studio, which I’m betting will continue to get better and better. I’d like to have C# (which I do with Xamarin and such) and a whole ton of other scaffolding and crud tools and other things that are available. I just prefer them without Windows.

As I often say, to each their own. Mine just isn’t Windows these days.

OS-X and F# [Clone It, Build It, Install It, Hack It]

Ok.

Mission: Get F# running on OS-X and executing via repl.

There are a number of steps here, that if you don’t have everything covered things just won’t work. So let’s knock out the prerequisites first. This will include getting autoconf installed. There are some other tools that I’ve added below that are good to have installed too, so get autoconf, automake, and libtool installed.

export build=~/devtools # or wherever you'd like to build
mkdir -p $build
 
cd $build
curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-2.68.tar.gz
tar xzf autoconf-2.68.tar.gz
cd autoconf-2.68
./configure --prefix=/usr/local
make
sudo make install
export PATH=/usr/local/bin
  
cd $build
curl -OL http://ftpmirror.gnu.org/automake/automake-1.11.tar.gz
tar xzf automake-1.11.tar.gz
cd automake-1.11
./configure --prefix=/usr/local
make
sudo make install
 
cd $build
curl -OL http://ftpmirror.gnu.org/libtool/libtool-2.4.tar.gz
tar xzf libtool-2.4.tar.gz
cd libtool-2.4
./configure --prefix=/usr/local
make
sudo make install

Now we’re ready to get some F# (64-bit flavors too) running on OS-X. This is very likely to take more than a few minutes because we’ve got two actual builds to do here.

First step is to get mono built and installed.

git clone https://github.com/mono/mono
cd mono
./autogen.sh --prefix=/mono64 --enable-nls=no
make
sudo make install

Now clone fsharp, build and install it.

git clone https://github.com/fsharp/fsharp
cd fsharp
./autogen.sh --prefix=/mono64
make
sudo make install

Finally get the binary executable paths added to the paths file.

vi /etc/paths

Add the following paths to the paths file.

/mono64/bin/mono
/mono64/bin

Once that’s done, run the tests to confirm everything has built right and is operable.

cd tests/fsharp/core
./run-all.sh

Now… that should all be ok.

repl

What I wanted now is something to sling some code and execute it. The easiest way, is to use the ‘fsharpi’ repl. At the OS-X terminal launch the repl.
Enter this line…

let x = 5;;

Then let y to a value…

let y = 20;;

Then enter…

y + x;;

…and you should see the math calculated. Then you can quit out of the repl with the following command.

#quit;;

The overall repl should come out looking like this.

> let x = 5;;

val x : int = 5

> let y = 20;;

val y : int = 20

> y + x;;
val it : int = 25
> #quit;;

- Exit...

Compilation – A Step Further

Just to show one more step. Let’s do a compile of a file with F# Code in it. Create a file called process.fs and enter the following code.

open System

[<EntryPoint>]
let main (argv :string[]) = 
    printfn "Hello World" 
    Console.ReadLine() |> ignore
    0

Now run the compiler ‘fsharpc’.

fsharpc process.fs

Now before you freak out screaming “OMG WTF am I supposed to do with a process.exe file…!!!” just calm down and execute the following command.

mono process.exe

There you’ll see the execution of “Hello World”. Welcome to F# on OS-X. More to come, Keep thrashing code!

Note: I’ve got a github repo for this and coming F# coding available at sharpgrounds.

Documentation First w/ README.md && Project Tree Build

I’m sitting here trying to get the folder structure for my project into a kind of ASCII Tree or something. I wasn’t going to manually do this, it would be insane. Especially on any decent size Enterprise Project with an endless supply of folders and nested content. I went digging to come up with a better solution. On Linux I immediately found the Tree Utility which was perfect.

Except I was on OS-X.

First option I gave a go to was to build the thing. Because I like to do things the hard way sometimes. First I needed to get the source, which is available here.

curl -O ftp://mama.indstate.edu/linux/tree/tree-1.7.0.tgz

Once downloaded, unzip the source into a directory and find the following section for the particular operating system you want to use the utility on. The section for OS settings looked like this when I finished editing it.

# Uncomment options below for your particular OS:

# Uncomment for OS X:
CC=cc
CFLAGS=-O2 -Wall -fomit-frame-pointer -no-cpp-precomp
LDFLAGS=
MANDIR=/usr/share/man/man1
OBJS+=strverscmp.o

Now get a good build of the command file.

./configure
make

Now let’s get tree into the executable path.

sudo mkdir -p /usr/local/bin
sudo cp tree /usr/local/bin/tree

Make sure your ~/.bash_profile is setup right, include this.

export PATH="/usr/local/bin:$PATH"

Reload the shell and tree should be available as a command.

The other option which is really simple, if you don’t want to compile to code, is to just use brew to install it.

brew install tree

So now you can use tree, and do cool stuff like pipe it out to a file. If you’re running this against a Node.js Project you may want to delete the node_modules directory and then just reinstall it after running the tree command.

tree > prof-tree.md

Then in your README.md file you can include the folder structure in the description of the project. Here’s a sample output!

.
├── README.md
├── client
│   └── README.md
├── package.json
├── proj-tree.md
├── server
│   ├── boot
│   │   ├── authentication.js
│   │   ├── explorer.js
│   │   ├── rest-api.js
│   │   └── root.js
│   ├── config.json
│   ├── datasources.json
│   ├── middleware.json
│   ├── model-config.json
│   └── server.js
└── test
    └── test_exists.js

4 directories, 14 files

That’s a super easy way to offer better documentation that provides some real insight into what various parts of the project structure are actually for.

Computer Repair Shit Storm

Notes From the Front: 5 Minutes With Visual Studio #Code

Ok, so Microsoft released a Visual Studio version on Linux and OS-X called Visual Studio Code. It’s also available for Windows but it’s so minimalistic compared to Visual Studio one might not want to use it on Windows.

Getting Setup on Ubuntu

Getting Setup on Ubuntu

There is however potential for this new IDE that Microsoft has released. It’s minimal and super fast at this point. On OS-X you can set it to launch as many of us OS-X users use Sublime (or your favorite editor here) to open entire projects.

Starting

Add this to the end of your bash startup script and you’ll have the magic sauce available via the command line.

code () {
    if [[ $# = 0 ]]
    then
        open -a "Visual Studio Code"
    else
        [[ $1 = /* ]] && F="$1" || F="$PWD/${1#./}"
        open -a "Visual Studio Code" --args "$F"
    fi
}

You’ll then be able to open projects with the standard command notation as shown.

✔ ~/Codez/React-Studies [master|…9]
16:28 $ code .

That pulls up a project in the editor just like this.

Visual Studio Code in Action

Visual Studio Code in Action

From there, just do what ya do and sling some code. There’s other features that are detailed on the Visual Studio Code site, but I’ll let you read up on those there.

Git Integration

The next thing I thought was pretty cool was the git integration, if for any reason because it just kind of looks nice. Nothing revolutionary here, but it’s nice to easily see without diving out to the bash to see what’s up.

Git Integration

Git Integration

…and the commit screen…

Committing and Commit Messages

Committing and Commit Messages

Now mind you, you can commit but not attach to any remotes and actually work with those. That’s kind of… disconnected? It’s fine though, whatever.

Quick Summary

So that’s my 5 minutes review. My main takeaway from all of this though, is that Visual Studio Code is not ready for prime time usage. It’s sorely missing a ton of features or capabilities that other editors, like Sublime or Atom, already have. I’m sure in the coming versions there will be more features and capabilities added, but currently I’ll be sticking to my WebStorm, Atom, Sublime, or Brackets usage for development needs still. For existing or future C#/F# Development I’ll just be using Xamarin’s tools most likely or diving into a Windows VM with full fledged Visual Studio. Until the future, I’ll just have to keep an eye on Visual Studio Code.

Truly Excellent People and Coding Inspiration…

.NET Fringe took place this last week. It’s been a rather long time since my last actual conference that I actually got to really attend, meet people, and talk to people about all the different projects, aspirations, goals, and ideas about what’s next for the future. This conference was perfect to jump into, first and foremost, I knew it was an effort in being inclusive of the existing community and newcomers. We’d reached out to many brave souls to come and attend this conference about pushing technology into the future.

I met some truly excellent people. Smart, focused, intent, and a whole lot of great conversations followed meeting these people. Here’s a few people you’ll want to keep an eye on based on the technology they’re working on. I got to sit down and talk to every one of these coders and they’re in top form, smart, inventive, witty and full of great humor to boot!

Maria Naggaga @Twitter

I met Maria and one of the first things I saw was her crafty and most excellent art sketches around lifestyles, heroes, and more. I love art like this, and was really impressed with what Maria had done with her’s.

Maria giving us the info.

Maria giving us the info.

I was able to hang out with Maria a bit more and had some good conversation time talking about evangelism, tech fun and nonsense all around. I also was able to attend her talk on “Legacy… What?” which was excellent. The question she posed in the description states a common question posed, “When students think about .Net they think: legacy , enterprise , retired, and what is that?” which I too find to be a valid thought. Is .NET purely legacy these days? For many getting into the field it generally isn’ the landscape of greenfield applications and is far more commonly associated with legacy applications. Hearing her vantage point on this as an evangelist was eye opening. I gained more ideas, thoughts, and was pushed to really get that question answered for students in a different way…  which I’ll add to sometime in the future in another blog entry.

Kathleen Dollard @Twitter && @Github

I spoke to Kathleen while we took a break across the street from the conference at Grendal’s Coffee Shop. We talked a lot about education and what is effective training, diving heavily into what works around video, samples, and related things. You see, we’re both authors at Pluralsight too and spend a lot of time thinking about these things. It was great to be able to sit down and really discuss these topics face to face.

We also dived into a discussion about city livability and how Portland’s transit system works, what is and isn’t working in the city and what it’s like to live here. I was, of course, more than happy to provide as much information as I could.

We also discussed her interest in taking legacy shops (i.e. pre-C# even, maybe Delphi or whatever might exist) and helping them modernize their shop. I found this interesting, as it could be a lot of fun figuring out large gaps in technology like that and helping a company to step forward into the future.

Kathleen gave two presentations at the conference – excellent presentations. One was the “Your Code, Your Brain” presentation, talking about exactly the topic of legacy shops moving forward without disruption.

If you’re interested in Kathleen’s courses, give a look here.

Amy Palamountain @Twitter && @Github

Amy had a wicked great slides and samples that were probably the most flawless I’ve seen in a while. Matter of fact, a short while after the conference Amy put together a blog entry about those great slides and samples “Super Smooth Technical Demoes“.

An intent and listening audience.

An intent and listening audience.

An intent and listening audience.Amy’s talked at the conference was titled “Space, Time, and State“. It almost sounds like we could just turn that into an acronym. The talk was great, touched on the aspects of reactiveness and the battle of state that we developers fight every day while building solutions.

We also got to talk a little after the presentation, the horror of times zones, and a slew of good conversation.

Tomasz Janczuk @Twitter && @Github

AAAAAaggghhhhhh! I missed half of Tomasz’s talk! It always happens at every conference right! You get to talking to people, excited about this topic or that topic and BOOM, you’ve missed half of a talk that you fully intended to attend. But hey, the good part is I still got to see half the talk!

If you’re not familiar with Tomasz’ work and you do anything with Node.js you should pay close attention. Tomasz has been largely responsible for the great work behind Edge.js and influencing the effort to get Node.js running (and running damn well might I add) on Windows. For more on Edge.js check out Act I and Act II and the Github repository.

The Big Hit for Me, Distributed Systems

First some context. About 4 years ago I left the .NET Community almost entirely. Even though I was still doing a little work with C# I primarily switched stacks to other things to push forward with Riak, distributed systems usage, devops deployment of client apps, and a whole host of other things. At the time I basically had gotten real burned out on where the .NET Community had ended up worldwide, while some pushed onward with the technologies I loved to work with, I was tired of waiting and dived into some esoteric stuff and learned strange programming techniques in JavaScript, Ruby, Erlang and dived deeper into distributed technologies for use in application construction.

However some in the community didn’t stop moving the ball forward, and at this conference I got a great view into some of that progress! I’m stoked to see this technology and where it is now, because there is a LOT of potential for a number of things. Here’s the two talks and two more great people I got to see speak. One I knew already (great to see you again and hang out Aaron!) and one I had the privilege & honor to meet (it was most excellent hanging out and seeing your presentation Lena).

Aaron Stonnard @Twitter && @Github

Aaron I’d met back when Troy & I put together the first Node PDX. Aaron had swung into Portland to present on “Building Node.js Applications on Windows Azure“. At .NET Fringe however Aaron was diving into a topic that was super exciting to me. The first line of the description from the topic really says it all “Distributed computing in .NET isn’t something you often hear about, but it’s becoming an increasingly important area for growing .NET businesses around the globe. And frankly it’s an area where .NET has lagged behind other runtimes and platforms for years – but this is changing!“. Yup, that’s my exact pain point, it’s awesome to know Aaron & Petabridge are kicking ass in this space now.

Aaron’s presentation was solid, as to be expected. We also had some good conversations after and before the presentation about the state of distributed compute and systems within the Microsoft and Windows ecosystem. To check out more about Akka .NET that Aaron & Andrew Skotzko …  follow @AkkaDotNet, @aaronontheweb, @petabridge, and @askotzko.

Akka .NET

Alena Dzenisenka @Twitter && @Github

...

…Lena traveled all the way from Kiev in the Ukraine to provide the .NET Fringe crowd with some serious F# distributed and parallel compute knowledge in “Embracing the Cloud“!  (Slides here)

Here’s a short dive into F# here if you’re unfamiliar, which you can install on OS-X, Windows or whatever. So don’t use the “well, I don’t use windows” excuse to not give it a try! Here’s info about MBrace that  Lena also used in her demo. Also dive into brisk from elastacloud…

In addition to the excellent talk that Lena gave I also got to hang out with her, Phil Haack, Ryan Riley, and others over food at Biwa on the last day of the conference. After speaking with Lena about the Ukraine, computing, coding and other topics around hacking and the OSS Community she really inspired me to take a dive into these tools for some of the work that I’m working on now and what I’ll be doing in the near future.

All The Things

Now of course, there were a ton of other people I got to meet, people I got to catch up with I haven’t seen in ages and others I didn’t get to write about. It was a really great conference with great content. I’m looking forward to round 2 and spending more time with everybody in the future!

The whole bunch of us at the end of the conference!

The whole bunch of us at the end of the conference!

Cheers everybody!   \m/

An Aside of Blog Entries on .NET Fringe

Here are some additional blog entries that others wrote about the event. In addition to these blog entries I’ll be updating this entry with any additional entries that I see pop up – so if you post one let me know, and I’ll also update these talks above that I’ve discussed with videos when they’re posted live.

The Idea of .NET Fringe…

I’ve been meaning to sit down and write up some thoughts on the coming .NET Fringe Conference here in Portland. Being held at the Bossanova Ballroom it’s not your normal tech conference – being that Troy Howard, Glenn Block, the team, and I wouldn’t be putting on a corporate style conference – we’re community grassroots hard core. There’s going to be some hard core tech conversations about the direction of .NET, and hard core conversations about so many of the open source aspects of that tech stack.

With topics ranging widely, one of the topics that really has interested me is the Akka .NET framework for a multitude of reasons. Partly because I’ve already played around with the original Akka Framework and have worked with Erlang. For more on their connectedness, check out actors for Akka and Erlang and dive actor model, passing and into the respective concurrency searches.

But as I started to write up thoughts about what I hoped to learn, experience, and who I wanted to meet and discuss these things with at .NET Fringe …  a host of blog entries appeared over the last few weeks mirroring many of my thoughts.

Christos Matskas @christosmatskas

Guess Who’s Attending & Speaking at .NET Fringe?

Last night, I spent over 3 hours on Skype with Glenn, who took time off his busy schedule to help me arrange tickets, accommodation, visas etc and stayed on until he was certain I was all sorted for my trip. He deserves more than a big thank you and I will make sure I convey my gratitude when I shake his hand in person!

As I’m writing this, I can barely contain my enthusiasm counting the hours to my first trip to the US and my first conference outside Europe.

Glenn Block @gblock

.NET Fringe – Defining the Future

There’s too many examples to name all but I’ll list a few recent projects that illustrate this : jQuery, NuGetGithub,JSON.NET, AutomapperXamarinNancyFX, and .NET vNext. This is just a sampling that does not do justice as there are many many other examples.

This change is important. This is just the beginning, but it’s a great beginning. A group of us think this is so important, that we’re putting together an event focused on this topic, .NET Fringe.

We’re bringing together members of the .NET OSS community that have been working to define the future. They are going to share their works, share their learnings, and share their passion. And it’s happening in Portland, a place rich in OSS culture.

Itamar Syn-Hershko @synhershko

.NET Fringe Let’s Build a Stronger Community Around OSS & .NET

For many years now the .NET framework and its ecosystem are viewed as a Microsoft thing, where its a product by a company and you either opt to use it (on Windows servers only) or not. Unlike other ecosystems, the community seemed to have no control over the direction the technology takes; the community has to align with Microsoft’s view which, as you’d expect, isn’t always what the users wanted.

While it was true for many years and some of it still is, things are changing. Many Microsoft projects are now open-source, on github, and accepting Pull Requests. A lot of development is now happening in the open, in that context the weeklyASP.NET Community Standup deserves a mention.

Microsoft is changing, for real. It is my belief that we, as a community, need to step up and strike while the iron is hot to shape the future of the .NET ecosystem.

Iris Classon @IrisClasson

Welcome to .NET Fringe in Portland Oregon

Instead of a quote, I’ll just let Iris’ do the talking…   ;)

Shawn Wildermuth @shawnwildermuth

.NET Fringe is Coming!

As many of you know, I’m not in the country at the moment but if I were, I’d be going to.NET Fringe in Portland, Oregon on April 12-14th. This new conference is all about open source in the .NET space and I and really excited that a conference is focused on it.

I have a couple of small, older .NET open source libraries, but my real facination has been with where the overall community is going. Both Microsoft and the community at large are all going open source and it’s great news for us all I think.