Apex for humans

19
Apex for Humans (and recently turned zombies) Kevin Poorman Principal Architect @CodeFriar Hey, I know we just met, and I know this’ll sound crazy but here’s my twitter: @codefriar, so follow me maybe?

Transcript of Apex for humans

Apex for Humans (and recently turned zombies)

Kevin Poorman

Principal Architect

@CodeFriar

Hey, I know we just met, and I know this’ll sound

crazy but here’s my twitter: @codefriar, so follow

me maybe?

Place

Customer or

Partner logo in

white area of

slide, centered

Kevin PoormanPrinciple Architect.

AgendaOur Goal: Ensure everyone has the capability to read and understand Apex.

• A note on the philosophy of language

• Grammar school

• Diagram all the things!

• There will be a quiz

Metaphors we live byA quick recap of vocabulary from third grade

• Metaphors are statements of comparison

between two objects that have a

non-logical, or non-obvious similarity.

• Similes are like Metaphors, but they use

‘Like’, or ‘As’ to make the comparison. (see what I did there?)

It's language for everybody, there is no difference!

Language, regardless of it's primary usage

for human or computer communication;

utilizes metaphor to help assign

meaning to objects and actions.

So why do we call them programming languages?

• Because they utilize metaphor to help assign meaning.

• In addition to the use of metaphor, computer languages have the following traits as

well:

– Grammar

– Dialect

– Idioms

– Vocabulary

Grammar is Hard. Lets go to the Expo floor.The grammar, or “syntax” of a language’s written form is the first hurdle to learning

any language.

• It’s also the easiest thing to learn about

a language. We pick it up, just by using

the language!

• That said …

Why is it hard?

• Grammar has subtle, often physically hard

to see marks.

• Consider:

– Let’s eat Grandma!

– Let’s eat, Grandma!

The single most likely cause of an extinction-event

level robot rising is a software grammar bug. – me.

Use to

introduce a

demo, video,

Q&A, etc. Diagraming all the code!Or: Learn you some apex grammar for great good!

Ground Rules

• Apex’s grammar says that complete thoughts are

ended with a semi-colon rather than a period

– We call complete thoughts “statements”

– Incomplete thoughts are “expressions”

• Additionally, Apex’s grammar dictates that

paragraphs, are grouped by { and } rather than

indentation and line breaks.

– Rarely are the {} on the same line.

• Most importantly: You are a Salesforce

Developer.

Ground Rules

• Variables

– Proper Names

• Types. Literally the hardest part of this.

– Apex is strongly typed, which is zombie speak for saying

that it’s a rather dumb language that demands you tell it

what kind of variable you’re creating.

– All Standard Objects are types

– All Custom Objects are types (Zombie__c)

– Built in types for Integer, String, Boolean etc.

– Type_name variable_name …

– Variable_name = (type_name) …

Ground Rules

• Methods

– “Last year at Dreamforce …”

– Also typed. You have to specify what kind of data the

method is going to return.

• Keywords / Reserved Words.

– Kind of like curse words, regardless of the language you

have to learn what you can and can’t say.

– abstract, break, catch, class, continue, do, else, enum, extends, false,

final, finally, for, global, if, implements, instanceOf, interface, new, null,

override, private, protected, public, return, static, super, testmethod, this,

throw, transient, trigger, true, try, webService, while, 'with sharing',

'without sharing' and virtual.

Ground Rules – last one I promise

• Sometimes we have complex types that only a

compiler could love.

– List<type_name> i.e.: List<Account>

– Set<type_name> i.e.: Set<Contact>

– Map<Set_type_name,List_Type_name> i.e.:

Map<Id,Zombie__c>

– Think about a roll of crackers.

Tasty tasty brainz crackers.

Use to

introduce a

demo, video,

Q&A, etc. Now for the Quiz(es)This is the interactive part, don’t make me call on you third person from the left in row

5.

Diagraming some Code

1. Type listType = Type.forName('List<' + objType + '>');

2. if (listType == null) {

3. return makeError('The requested resource does not exist',

'NOT_FOUND');

4. }

This code snippet has Statements, one Expression and one Paragraph. Can you

find them?

For 10,000 internet points* What line contains the creation of a variable and what’s

its type?

*redeemable only on the third Tuesday of the 5th month after the first blue moon for funny-cat-photos

Diagraming some Code

1. Zombie__c mattyb = Type.forName('List<‘Zombie__c’>');

2. Id objId = (id) ‘001abc1234LAKFR’;

3. String awesomeSauce = ‘Awesome Sauce’;

4. Account ZombieAccount = new Account();

For another 10,000 internet points, which of these has the type …

Diagraming some Code

1. Public Static Country__c getCountry() {

2. Integer i = TestUtils.getRandomNumber(10000);

3. return new Country__c(Name = 'Test Country' + i,

4. Sub_Region__c = 'Test Region’+ i,

5. Region__c = 'Test Location' + i,

6. English_Speaking__c = 'Yes');

7. }

Use to

introduce a

demo, video,

Q&A, etc. Questions & Answers.