Original thoughts on Functions, need insight on safety of optimization depending on return behaviour.

I’m currently working on an ML-family programming language in specialized for minimization of executable-size (e.g. for embedded systems).

On the function front it (vapour-ware-style) features a notable innovation: A very full set of function “tags” with a simple inference algorithm.

Function “tags” is stuff like “pure” and “noreturn.”

What I am working with is a Lattice (partial order with lower and upper bounds,) over these with the ordering relation being “… can be safely used as if it were a …” so for instance a pure function can be safely used as if it were an impure one (or to put it another way, a pure function is an impure function with a side-effect count of zero.)

The properties I am working with are these:

  • Number of calls allowed: any, maybe_once, once_or_more, and once_only, all of which are intervals of integers, [1,1]; [0,1]; [1,∞); and [0,∞) respectively. Ordering relation is set-inclusion (e.g. a maybe_once can be safely used as a once_only function because {1} ⊆ {0, 1}).

    An example of a once_only function is a raw resource-deallocator; an example of a maybe_once function is a library initializer (i.e. you can choose not to initialize the library, but initializing twice f***s it up), an exmaple of a once_or_more function is an idempotent/safe resource-deallocator

  • Purity: side_effects, invisible, and pure. The in-between point of invisible is a function which does not change the memory space immediately visible to the caller. The safe-use ordering should be obvious.

    An example of a side_effects function is one which changes a global variable, an example of an invisible function is one which prints to stdout (hard to tell, need third-party library calls to check), an example of a pure function is a simple implementation of greatest common divisor.

  • Closure properties: closure/delegate or raw. Discerns whether a callable object has attached data like curried arguments, an object of which it is a method, or C-style static variables. A raw function is essentially a closure function with zero attached data.

  • Reference properties: referencing or self_contained. Discerns whether a function has references to external data, such as global variables or variables local to the parent scope.

    An example of a referencing function is a block function from Ruby or Rust. A self_contained function is a referencing function with zero external references.

  • Lastly, return-behaviour: no_return, maybe_return, always_return. A classic no_return function is C’s terminate(), most pure functions are always_return, a function which exits on error is a maybe_return.

Now, on the return behaviour I am uncertain of the “safe-use” ordering. Should maybe_return be the “safest” element, which no_return and always_return can default to (and where no_return and always_return can never be used for one another) or shall always_return be the “safest” (where no_return is then the least safe, because you can unambiguously state that a no_return returns a type, but it will return the bottom element of that type).

To me, the first option (maybe_return as “safest”) is the more optimization-minded, while the second (always_return as “safest”) seems to make maybe_return superfluous (which it might be) and is more type-theory-ish.

These five lattices are then joined in a direct product:

  • (num, pur, clo, ref, ret) < (num', pur', clo', ref', ret') iff num < num', pur < pur', clo < clo', ref < ref', ret < ret' .

The inference algorithm is:

  • The greatest lower bound of the greatest lower bounds of all function calls in each execution path in the function.

In pseudo-python:


def infer(func): res = None for path in func.execution_paths(): x = None for func in path.get_functions_called(): if x is None: x = func else: x = greatest_lower_bound(x, func) if res is None: res = x else: res = greatest_lower_bound(res, x) return res

These tags are part of the function type and exist mainly for ensuring programming safety.

Thoughts? Especially on the order of return properties?

[Python] I finished Codecademy’s course… Now what?

It feels like I have the very basics, but still lack a lot of the more advanced stuff, how do I proceed from here?

Is it a good idea to ditch Python and start learning a lower level language? Or should I learn more around Python before moving to another language? (if so, where/how?)

(PS: my goal is programming AI)

Getting a job

Hi all,

I’m a 17 year old web dev in UK – been coding since the age of 12. My primary language is PHP (I know a lot of you guys don’t like it), but I’m also fairly decent with Python.

For the past five years, I’ve been teaching myself the best possible practices. I’ve studied OOP, TDD, DDD, etc. and it’s been a whole lot of fun, but I’m getting to the age where I’m expected to have a job.

I’m committed and motivated and have many character references (from ex-teachers and people I’ve freelanced for) to back that claim up so getting a job at the local coffee shop for minimum wage probably wouldn’t be too difficult, but if possible I’d really like to pursue my passion.

The problem is, I live in a relatively small town with no web dev agencies. The closest one is about 35 miles away and since I don’t drive and don’t have cash for train tickets etc., it’s not very viable.

What would your suggestion be? I’ve been doing this for so long and love it so much. I don’t want to give it up just like that.

Beginner coming from Python to Java, some help needed please

I have just finished my first semester of Comp Sci and took a 101 course in programming that used Python. I’m taking more Comp Sci papers next semester and want to use the break to further my Python and bring my Java up to my current Python level. I’ve started working through learn Java the hard way but there are a few things I’m confused about with Java.

  • What is this “public static void main( String[] args )” business? I have no idea what any of that means.

  • Why can I put System.out.println(“Hello” + 5) ? I mean in Python you cannot add an int to a string.

  • Is the actual Java language a lot smaller than Python? By that I mean, I was trying to do some user input, in Python its as easy as input(“Type something here: “) and that gets assigned to a variable. In Java you have to import a library just to get user input.

Thank you in advance for your answers

I’m an ancient PHP developer who could really use some help embracing the new, better way of doing things!

I have been using a LAMP stack almost all my life. On top of LAMP I usually use a wrapper for mysql, RainTPL for templates and jQuery. No other frameworks. I’ve worked with frameworks like CakePHP about 3-4 years ago but I have always felt like they were in my way rather an helping me do things faster.

Web development has always been a hobby rather than a career, so I was always a little behind, and now even more so after taking a two year hiatus. All of a sudden I feel like a dinosaur. So many different, competing technologies and I feel so lost. Like many of the legacy PHP developers I am mainly a Javascript user, not a developer. Everything seems to be on Javascript or Python nowadays.

I’ve recently moved to a Digital Ocean VPS from shared hosting. I felt like I got out of jail and I could do anything I wanted. I’ve switched my site from Apache to nginx, and with some further optimizations the load times now are almost a quarter of what they used to be. This made me realize how different and better things are right now and has given me a new drive to explore new things.

I have another big project coming up and I could really use some help catching up, especially the sort of technology that I should use.

What the project is:

It’s a local restaurant directory in the form of a website and mobile apps. We are going to offer curated, individually managed profiles for local restaurants that will promote their strengths, discounts and coupons. The app will help the town residents discover new places to eat and discount coupons to save money.

Requirements:

Frontend:

  • Search as you type. Every piece of data we have on the restaurants will be searchable, and the results should show up as the visitor types.
  • Has to be extremely fast. Whether it’s the mobile app or the website, querying the database has to be super fast. I’m pretty happy at Digital Ocean and that’s where I’ll be hosting it. With my own VPS I guess I can use any technology available. PHPfpm + Nginx is pretty fast, but I wonder if there’s something even faster!
  • Tags for restaurants. I haven’t really worked with tags before, so I’m not entirely sure how to go about it the best way.
  • Multiple image galleries per restaurant.

Admin Panel:

  • Ability to upload images into multiple galleries per restaurant. Basic image editing capabilities like resize and crop.
  • I need a relational database to store coupons, galleries etc. for each restaurants. They’ll be searched through a lot, so a fast DB would be preferable.
  • Good admin panel to CRUD restaurants and coupons.

User Interaction:

  • User won’t have any accounts, or preferences to save. They’ll basically just arrive at the site/app and browse/search through the restaurant catalog. For the mobile app I’d like the use their location information to order the list of restaurants.

Mobile App:

  • I need to create an iPhone app and an Android app for the site. This is more important than the desktop site.
  • From what I’ve found it seems that the best way to go about it is creating a REST API for my restaurant database and use AppGyver Steroids or Composer to construct the app.
  • Performance again is the key, but I have no prior experience developing an app. So I think a cross platform solution would be better suited, even though they can’t match the native code performance.

What I’ve found so far:

From what I’ve researched so far, my options are:

  • Stick with PHP and use a framework like Laravel + AngularJS
  • Learn JS properly and use Node.js via KeystoneJS
  • Learn Python and use Django

I’m willing to learn a new language if it’ll provide significant performance benefits. I’ve traditionally been a C++ developer so I’m more comfortable with OOP than spaghetti code. Browsing through JS and Python codes it seems that they wouldn’t be very hard to pick up on to produce acceptable code.

What I’m really looking for is your opinions on the best way to tackle this problem. You guys have way more experience with these new tech than I have, and I’d really appreciate your advice on the best way to tackle this project.

My apologies if I have failed to give any crucial information, I’ll be glad to provide it if you ask.

Thanks!