#1000 A Suggestion: More API Info

casey Wed 3 Mar 2010

Hello! I'm a high school student who recently discovered Fantom and I really like it. I've had previous experiences with Java and Ruby, so the familiarity is nice. Still, I'm getting quite confused with some of the API stuff. The examples are really hard to follow for me. I've read through the langDoc and use it for a reference, but without any tutorials I'm kind of lost. For instance, in the fwt hello world program, there is use of Window. I've found that Window is an fwt class. However, no constructor is called to make a new object and no inheritance is used so I'm unsure of what is really happening with the use of the Window class here. The documentation for everything else is great but the examples for the APIS are very complex and don't do too much to explain what the code does. Some simple tutorials or guides of how to use the API classes to make smaller programs would be very helpful.

Keep up the great work, though! I just felt like expressing my concern. I have not worked with graphical APIs before and have only scratched the surface in other APIs in other languages, so I'm not very good at this stuff yet.

tcolar Wed 3 Mar 2010

The FWT code makes heavy use of ItBlocks, which lookd a little weird if you have never seen one before, but once you are used to it, it's much more compact & elegant than swing.

See: http://fantom.org/doc/docLang/Expressions.html#itBlocks

It also makes heavy use of the comma operator ("Collections" paragraph, right after itBlocks)

If you have time, review most of the the docs under http://fantom.org/doc/docLang/index.html, it's time well spent.

casey Wed 3 Mar 2010

Thanks for the link. I understand the it-blocks better now and I'll re-read some of the stuff in the documentation. I really see the usefulness that these types of blocks provide, so I'll make sure to try and master them!

tactics Thu 4 Mar 2010

Don't miss out on the examples documentation. All the source code is packaged and ready to build and play with (just run fan build.fan).

http://fantom.org/doc/examples/index.html

casey Thu 4 Mar 2010

That's part of what I'm talking about. The fwt demo is so crazy in the amount it covers that it seems a bit threatening. I should be able to make more sense of it now, though. Some of the examples are very easy to understand, as well. I'd just suggest some comments in there or a paragraph description. Some day, this might be someone's first language and having written explanations would really help (or maybe there is a file like that already containing descriptions I've missed). Like I said though, most of the tutorials are easily understandable and can be managed as-is.

On a sidenote: fan build.fan returns an error of an invalid type signature. Thanks for the quick and helpful responses!

tactics Thu 4 Mar 2010

On a sidenote: fan build.fan returns an error of an invalid type signature. Thanks for the quick and helpful responses!

Could you post the error?

For Window in particular, does have a constructor. It's ftw::Window.make. Note that the new keyword in Fantom marks a slot as a constructor.

Here is a short script you can run to create a new empty window with a title.

using fwt

class Foo
{
  static Void main() 
  {
    window := Window.make
    window.title = "Test"
    window.open
  }
}

By convention, constructors are called make. You can have as many constructors as you want and name them whatever you want, but make is what you might call the "default" constructor in other languages.

If you use parentheses on a type name without giving a method, you are actually making a call to make. So window := Window() and window := Window.make are the same. (The first one is actually perferred).

Then there are it blocks, which look the "weirdest" but turn out to be really handy.

class Foo
{
  static Void main() 
  {
    window := Window
    {
      title = "Test"
    }
    window.open
  }
}

The exact details of how it blocks work are a little tricky, but you can read it like: a new Window object with title "Test". Behind the scenes, Window.make is being called.

All three ways work.

casey Thu 4 Mar 2010

I believe the error is somehow related to the fact that the fan command will only work in the \bin directory. According to the third method, it-blocks omit the constructor (which is what I had believed for a bit). I'm back on track now. Thanks once again.

tactics Thu 4 Mar 2010

the fan command will only work in the \bin directory

I don't think is the cause of your problem, but this means you need to set your PATH environment variable.

http://www.java.com/en/download/help/path.xml

When you type a command at the command line, your operating system uses the directories listed in your PATH variable to figure out which one to execute.

Setting your PATH is something you have to do with all command line-based tools, although ometimes it's done automatically for you when you first install a piece of software.

By the way, what kind of tutorials would you like to see? I'm considering writing a series of tutorials on the language eventually. What would you like to do with Fantom? I'd also like to hear about things in the language where you get stuck or frustrated.

Happy hacking.

casey Thu 4 Mar 2010

I do have the path set, but, as I've said, the fan command will not run outside of the C:\fantom-1.0.51\fantom-1.0.51\bin directory. The build.fan file is located in the \src directory.

As for tutorials, I'd just like simple steps which continually build off of each other for API-related things.

I actually would write some tutorials myself for the absolute beginner. I have learned quite a bit about programming from books where the information is organized in a meaningful way and things go in-depth. I'm used to seeing code but also having it explained.

I'd really just like examples of how different API classes are used and they synchronizing the classes into a program, one by one, explaining each step. Reiner's XNA tutorial is the closest thing I can think of at the moment.

tactics Thu 4 Mar 2010

What's your PATH set to exactly? You can print it out at the command like like this:

C:\> echo %PATH%

It could be a few different issues. You have to restart the command prompt whenever you change the PATH. Alternatively, your PATH may not be correct. It may point to the wrong directory ("\fantom-1.0.51" instead of "\fantom-1.0.51\bin") or it may be a misspelling.

If you need any help getting your environment set up, send me an email at tactics40@gm ail.com.

casey Fri 5 Mar 2010

My PATH is set to C:\fantom-1.0.51\fantom-1.0.51\bin. That's how my other things listed in PATH are listed.

msl Fri 5 Mar 2010

I don't think the issue here is necessarily PATH related as to get an invalid type signature things are obviously getting fired off to some point.

What's the path you're running from, and what's the exact message/stack trace?

Login or Signup to reply.